views:

296

answers:

2

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)

+1  A: 

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.

http://stackoverflow.com/questions/1441406/how-do-i-access-a-file-share-programattically

David Stratton
Looks promising, thanks. Should probably search a bit harder.
rojoca
Don't worry about searching harder. I mean it's a good idea, but don't kick yourself for not finding it. The question was phrased differently so it would have been hard to find. I just happened to have seen that one and it was fresh in my head.
David Stratton
A: 

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

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

Scrappydog
Yeah it does have login as service rights
rojoca