Question

I have a C# .NET service that runs as DOMAIN\username on a windows server and it needs to access a network share \\share\export docs$\.

If I'm logged into the machine (as DOMAIN\username) I can see the share and I have even mapped it to X: and tried to use that. I set the path in app.config (and restart the service) and if I use a path on C: it works fine but if I try using \\share\export docs$\ or X:\ it can't see any of the files I need to access.

I have tried running the service as both a local user and as DOMAIN\username

Any ideas what I might be doing wrong?

EDIT: Stacktrace from log:

Could not find a part of the path 'X:\200909\11324709\coo.pdf'.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType)

at System.Net.Mail.Attachment..ctor(String fileName)

Was it helpful?

Solution

Mapped drives in .Net are a bit buggy. However, this type of situation comes up in questions here quite a bit. You wold be better to specify the UNC path.

This isn't the exact same question you asked, but this post is relevant to your question and should help you out.

How do I access a file share programattically

OTHER TIPS

Running your service as Domain\username "should" work.

Are you sure that account has "login as service" rights?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top