upload file to the network mapped drive in c# - c#

I am using c# asp.net mvc 3 and entity framework to upload the file to the network drive mapped as Z drive. I have following c# code for determining file path:
var path = Path.Combine(Z:/upload/catone/", fileName);
aries.SaveAs(path);
I am using window server 2008 and IIS 7. I have also check Security of upload folder of network drive and have acess full control for EVERYONE user. If I changed file path to local drive, it works fine. But it shows following error while uploading to network drive (Z:/).
Could not find a part of the path
'Z:\upload\catone\_2013011504265221N_todaily.wav'.

Your code is running under IIS and thus is run with access privileges of the IIS user account which may not have access to that network drive.
You can try runnning the app pool under your identity for instance, to rule this issue out, or give full access to the group IIS_IUSRS to that folder.

First of all save the file in local machine ,
than after use file.copy(Source, Destination, true) method to save file in network drive.
try that it is helpful for you

Related

Want to read/write file on network from my IIS but access denied

I want to copy one file on the network drive ex. 192.168.0.32/ODfolder
I have hosted C# API on my IIS but when I call API they give me the error "Access Denied"
but when i debug on localhost it will run fine without error and copy the file on the network drive too.
Regards
Rajat Khandelwal
First check whether that network drive is accessible from the machine where you have hosted your application, if yes then give write access on that folder to everyone or the user under which your application pool is running which is hosting your C# API.
Hope this helps. Happy coding...
Check which user you are connecting using .Local IIS uses IIS_USERS. change the user or add permissions to user connecting to the file.

Read/write files in shared drive from web application hosted on iis

We have two server in same domain. On one server (SERVER1) we have folder "C:\AppFiles\Production\Inbound" and shared AppFiles folder as a drive (AppFiles (O:)) to another server (SERVER2) and we are manually able to place files in shared drive (O:\Production\Inbound) on SERVER2. But we want to read/write files in shared drive (O:\Production\Inbound) from our mvc web application hosted on SERVER2.
We are getting below error in provided code when try to read/write in shared drive (O:\Production\
public void Writefile()
{
System.IO.File.WriteAllText(Path.Combine(#"O:\Production\Inbound", "testlog.txt"), "test test, text");
}
error:
Could not find a part of the path 'O:\Production\Inbound\testlog.txt'.
Please suggest how i can read/write files in shared drive from application hosted on iis.
Mapped drives are not supported on IIS, rather you can use UNC paths. Try changing the path to the following:
\\SERVER1\C$\AppFiles\Production\Inbound
If both the servers are on the same network and you can access the above link from server 2, the it should work.

Access password protected shared network

How to read/write files in a shared network drive?
I am creating an application to upload files to the password protected shared network drive. When I run locally, the files are uploaded well. But, in the publish environment it throws:
Access to the Path '/shared network drive/' is denied
How to resolve this ?
Two ways:
1) Create a network drive connection to the remote machine (so it appears to your computer as "X:" for example) and save to that.
2) Use the full UNC path specification: //RemoteMachineName/SharedFolder/foldername

Accessing an NFS share from a Windows service

I have a Windows service that can't access an NFS share on a UNIX box. I can't access the share with the UNC path, so I have to have it mounted.
I have a console application that can see the drive and runs fine, but when I deploy my Windows service, it can't see the drive.
I have the drive mounted as my local user as well as the administrator.
I've tried mounting a drive from my application by using "Process.Start(mBatchFilePath);", but that didn't work either.
I'm running as the local user (set as administrator).
Tried using a symbolic link
Going to try to set up an FTP to transfer the files
Does anyone have any suggestions on how I can make this work?
SOLVED: I used SSH.Net and transfer files with an SFTP server
I don't think that mapping the drive to a symbolic link is a real solution. The Problem is, that the service runs under a certain user account and thus it accesses all resources with the privileges of this account. Of course your IT admin is right, it's not a good idea to let the service run under the local administrator account.
You should create a new user account that is allowed to access the shared folder. Then set up the service that it runs under this account and the service should be able to access the network share. But remember, a network share that is mapped to a drive letter is only mapped for the current user. So the service (that runs under a different user account) simply doesn't have any drive with this letter, it is not mapped under its account.
So in your service you should always access the share with its full UNC path and not with a mapped drive letter.
Since we were connecting to a Solaris server from a windows box I needed to use SFTP to send files to the server.
I contemplated some sort of a folder sync, but it wasn't a route I wanted to go down.
I used the SSH.Net libraries.

Could not find a part of the path on windows azure

I deployed mvc-3 application on windows azure. In my application i am uploading the file an save it in the App_Data/DownloadedTemplates folder.
var path = Server.MapPath("~App_Data/DownloadedTemplates");
my application is running on staging environment currently. When i uploaded file , it shows me an exception in the browser :
Could not find a part of the path 'F:\sitesroot\0\App_Data\DownloadedTemplates\B.htm_2c77cdfd-c597-4234-bd1e-29ca0a9b8d0e.htm'.
I am using Server.MapPath to locate the path of App_Data on the server, now why this exception ?. Can anybody tell me the problem ?
You shouldn't be doing this in a Windows Azure application. In Windows Azure you should use LocalResources (reserved space on a dedicated disk) for saving temp files on the disk, this is the only place where you should store data.
Here is an example of how you would access such a LocalResource (name and size can be configured in the VS project):
LocalResource localResource = RoleEnvironment.GetLocalResource("DownloadedTemplates");
Don't forget that data in LocalResources might disappear (when the machine crashes for example). If you really want to persist your data, you should be using Windows Azure Blob Storage.

Categories