ASP.NET Hosting :: How to Upload File Using c#

Here i will shown how to upload a file using c#.Sending file from client system to server system called “file uploading” .this implementation is required in certain website like uploading resume,image and attachment towards email.File uploading control is provided asp.net to implement file uploading

The properties and methods of File upload:

*has file–true–>File is upload
false–>File is not uploaded
*posted file–content type–>it returns file types
text/plain—>normal text file
text/xml—->XML file
application/msword–>doc file
save as(file path)—>it will save upload file in server system
Here i will shown to allow user to upload photos(image file type of gif) .For this i have taken file upload control and button server control in aspx page.

Response.write(fileupload1.Hasfile);  Â
Response.write(fileupload1.filename);  Â
Response.write(fileupload1.posted file contenttype);  Â
if(fileupload1.Hasfile)  Â
   {  Â
   if(fileupload1.Postedfile.ContentType=="image/gif")  Â
      {   Â
       FileUpload1.postedfile.saveAs(server.mappath(".")+"\\"+fileupload1.filename);  Â
       Label1.text="upload successfully";  Â
      }  Â
      else Â
      label.text="upload gif file";  Â
    }  Â
    else Â
    label1.text="file required";  Â
   }  

Note:File upload control supports maximum of 4mb file size for uploading to server

You must be logged in to post a comment.

Sponsors

Advertise Here

Best Blog Hosting Provider

Cheap Reseller Hosting

Best European ASP.NET 4.0 Hosting Provider