Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all i am successfully uploaded image in network drive but now i unable to view that image from the same path please help me.
when i am save image in application only then just give the path for view button:-'../Images/Emp Docs/<%#Eval("Salary_URL")%>' it is working but whta can i do for network drive.


this is upload Code:
protected void btnUpLoad_Click(object sender, EventArgs e)
{
mydt = (DataTable)(ViewState["mydatatable"]);
//DataRow myrow = mydt.NewRow();
DataRow myrow = mydt.NewRow();

string filePath = Path.Combine("Z:\\", "Emp Docs");

//also tried below which works on local drive, but failed on mapped network drive
//string filePath = Path.Combine(Environment.CurrentDirectory, @"..\\..\\dev\\WebRootFolder\\SourceFolder\\ImageFolder");

HttpFileCollection uploadedFiles = Request.Files;

for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];

try
{
if (userPostedFile.ContentLength > 0)
{
//UploadLabel.Text += "File #" + (i + 1) +
// "

";

UploadLabel.Text += userPostedFile.FileName;


userPostedFile.SaveAs(filePath + "\\" +
Path.GetFileName(userPostedFile.FileName));

UploadLabel1.Text += filePath + "\\" +
Path.GetFileName(userPostedFile.FileName);
}
}
catch (Exception Ex)
{
UploadLabel.Text += "Error:
" + Ex.Message;
}
}

Posted

1 solution

Your first approach relies on a mapped drive configuration. A mapped drive is relevant only to the current user, so while you might be able to see z:, there's no reason that your web application which should be running under a dedicated secure account will have this mapping.

Your second approach only works on the local drive. You are trying to get the path that is derived from your current path. This will not pull in a network path.

What you need to do is use the UNC path to the folder. If you look at the mapping for your z drive, you will see what the physical path is. That must form part of your path.

I mentioned that your web application should be running in a separate account. You will have to assign the rights to access your UNC folder to the account otherwise it's not going to be able to see it. Your system administrators will have to do this for you.
 
Share this answer
 
Comments
Member 11221185 17-Feb-15 2:20am    
Hi thanks for the help. I already gives all the access rights to that folder. If i given the physical path like 'Z:\Emp Docs\<%#Eval("Salary_URL")%>'. but it shows blank when i click on view button.

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