Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a fileupload to use file upload i used this code-


Now when i select a file and upload it is working. When i do not select any file that time it is giving error--

Could not find a part of the path 'D:\Projects\VSimplify\Source\VSimplify\Images\Logos\'.

-----------
now i wnat to make file upload to not manditory with validation
Posted

You have to use FileUpload.HasFile Property.

Only if it has file, then get the path else dont.

Sample code.

C#
void btnSave_Click(object sender, EventArgs e)
{
  if (fileupload.HasFile)
    {
      fileupload.SaveAs(Server.MapPath(FileVirtualPath + fileupload.FileName));
     }
  Save();
}
 
Share this answer
 
Try this,

if (FileUpload1.HasFile){
//do your stuff
}
else{
  //leave it
}


cheers
 
Share this answer
 
v2
The fileupload control has a HasFile property. do all your fileupload related logic after checking for HasFile

C#
if(MyFileUpload.HasFile)
{
  //all file upload related code here
}
else
{
  //no issues, go ahead
}
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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