This article will contain the code to upload image in web server. This code uses the File control used to upload image the hosting server.
In the .aspx.cs file on button click event write the below lines of code
Button Click Event;
String strFilename, strMessage,strFoldername;
strFilename=fileUpload.PostedFile.FileName.ToString();
strMessage=uploadFile(strFilename, ConfigurationManager.AppSettings["folderPath"]);
Label1.Text=strMessage;
Label1.ForeColor=System.drawing.Color.Red;
//Method to store image in the server
Public string uploadFile(string fileName, string folderName)
{
if(fileName=="")
{
return "Invalid filename supplied";
}
if(fileUpload.PostedFile.ContentLength==0)
{
return "Invalid file content";
}
fileName=Path.GetFileName(fileName);
if (foldeeName=="")
{
return "Path not found";
}
try
{
if(fileUpload.PostedFile.ContentLength <=2048000)
{
fileUpload.PostedFile.SaveAs((folderName) + "\\" + fileName);
return "file upload successfully";
}
else
{
return "Not Upload file";
}
}
catch (UnauthorizedAccessException ex)
{
return ex.Message + "Permission to upload file deniec";
}
}
}