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:
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.