Can't write to a shared drive

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I thought I had my program working but now that did not seem to be the case.

I am trying to write from the server to a shared drive which we have set as
an H: drive.

When I run my web page from my local machine (VS) it writes correctly to the
H: drive.

But when I run it off the Server (which also has access to the H: drive it
says it can't find it.

For example, this is the path I am trying to use to write out my csv file:

H:\SHARE\Reports

But when I try to open it I get:

Could not find a part of the path
'H:\SHARE\Reports\043_051909_083109_Discrepancies.csv'.

Is there something I have to do in IIS to allow it to write to the folder?

Thanks,

Tom
 
Mark Rae said:
I've already explained this...

But I had already sent this before I saw your explanation.
It works on your local machine because your local machine has the shared
folder in question mapped as a network drive. To get this to work on the
webserver, you will either have to create the same mapped network share,
or reference the folder explicitly via its UNC path...

Also, as mentioned, my server has the same mapping:

H:/

Which as a folder Share which has a folder Reports.

And I access the drive like:

fs = new FileStream(fileName, FileMode.Create,
FileAccess.ReadWrite);
csvFileWriter = new StreamWriter(fs);

Where fileName is:

fileNameOut = @"H:\SHARE\Reports\file.csv;

So you are saying my server code should be able to write to this share as
long as the Server has access?

I just went on the Server, accessed the folder from Windows Explorer and put
a folder and a file in it and it worked fine - so the permissions are there.
H:\SHARE\Reports

Thanks,

Tom
 
Hi,
Also, as mentioned, my server has the same mapping:

H:/

This is not the server this is YOUR profile. Mapped drive are tied to a
specific user profile, they are not a server wide setting. For a web
application, I would strongly recommend using UNC names
(\\servername\share\name\path\file.txt) ...
 
Mark Rae said:
I've already explained this...

It works on your local machine because your local machine has the shared
folder in question mapped as a network drive. To get this to work on the
webserver, you will either have to create the same mapped network share,
or reference the folder explicitly via its UNC path...
The UNC path was what I needed to do.

I hadn't realized that the Mapping I did while logged on wouldn't apply to
the website which is running as a service.

That would also explain why it works when running out of VS. In that mode,
I am logged on so the mappings would apply.

Thanks,

Tom
 
Patrice said:
Hi,


This is not the server this is YOUR profile. Mapped drive are tied to a
specific user profile, they are not a server wide setting. For a web
application, I would strongly recommend using UNC names
(\\servername\share\name\path\file.txt) ...
That was it. Mark had also mention it but I hadn't tried it yet. I tried
the first thing he mentioned which was creating the mapped share on the
server.

That actually makes sense now that I look at it.

Works perfectly now on my server.

So, just out of curiosity, how would you map a drive for the server (not
that I would, just curious) - or can you.

Thanks,

Tom
 
Back
Top