Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Access to the path //172.20.2.50/sharedfolder/ is denied.

whereas, 172.20.2.50 is the IP of the other PC that is in same network, where i want to store my File....
Plz help me ...

What I have tried:

<pre>protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
 
            filename = FileUpload1.PostedFile.FileName;
            
            string filepathfb = "////172.20.2.50//sharedfolder//" + filename;
 
            FileUpload1.SaveAs(filepathfb);
Posted
Updated 13-Aug-17 22:28pm
v2
Comments
F-ES Sitecore 14-Aug-17 4:38am    
The default account your code runs under doesn't have network access, you need to change the anonymous IIS account to one that has the required access. Google for how to do that.

It's denied because the remote computer doesn't set permissions allowing you (the user on the webserver, which is probably an IIS login rather than a "real" user) to write files to that folder.

Check the permissions on the folder, or if you are doing this often, connect a drive letter to the shared folder (supplying the appropriate login details) and save direct to that disk instead of relying on the IP address each time.
 
Share this answer
 
Comments
Member 10611055 14-Aug-17 5:32am    
At localhost its working fine but only problem at IIS gives error: access denied ..Also Create a network drive connection to the remote machine(so it appears to remote computer as "Z:\) but same error occurred ...
OriginalGriff 14-Aug-17 6:21am    
No, you need to set up the drive on the computer running your website: the computer running IIS, not on the "remote computer" on 172.20.2.50 - and give the appropriate permissions when you set up the drive connection.
Your approach seems correct for saving a file to a shared folder on a network computer using ASP.NET. However, there are a couple of adjustments that you might need to make:

UNC Path Format: The UNC (Universal Naming Convention) path should be specified using double backslashes (\\) instead of forward slashes (//). The UNC path format should look like \\computername\sharedfolder.

File Path Formatting: Ensure that the file path is correctly formatted. In your case, you're using //// at the beginning, which is unnecessary. You only need two backslashes at the beginning for a UNC path.

Here's the corrected version of your code:

C#
protected void btnUpload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile)
    {
        string filename = FileUpload1.FileName;
        string filepath = @"\\172.20.2.50\sharedfolder\" + filename;
        
        FileUpload1.SaveAs(filepath);
    }
}

In this code snippet:

FileUpload1.FileName is used to get the name of the uploaded file.
@"\\172.20.2.50\sharedfolder\" specifies the UNC path to the shared folder on the network computer.
FileUpload1.SaveAs(filepath) saves the uploaded file to the specified path.
Ensure that the account under which your ASP.NET application runs has the necessary permissions to write to the shared folder on the network computer. Additionally, make sure that the network path is accessible from the web server hosting your ASP.NET application.
 
Share this answer
 
Comments
CHill60 15-Feb-24 9:39am    
Quote: "In your case, you're using //// at the beginning, which is unnecessary. You only need two backslashes at the beginning for a UNC path." Incorrect, or rather, Incomplete. The OP had "////172..." whereas you are using @"//172...". In other words the OP used an escaped string and you used a verbatim string. Net result is identical.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900