it works fine for just copy this and use if you face any problem i will tell you if you reply me...
in below code "fuphotos" is the id of my fileupload control
protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
{
HttpPostedFile oHttpPostedFile = fuphotos.PostedFile;
string uncFileName = string.Empty;
string ImageName = string.Empty;
string StrFileType = string.Empty;
string strunFilepath = string.Empty;
string strcFilepath = string.Empty;
string strcFilepath1 = string.Empty;
try
{
if (fuphotos.HasFile)
{
Normal image saving starts
StrFileType = oHttpPostedFile.ContentType.ToString();
if (StrFileType == "image/pjpeg" || StrFileType == "image/gif" || StrFileType == "image/jpeg" || StrFileType == "image/bmp")
{
uncFileName = oHttpPostedFile.FileName.Substring(oHttpPostedFile.FileName.LastIndexOf("\\") + 1);
string FolderName = "UNC_PhotoGallery\\";
DirectoryInfo thisFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\" + FolderName);
if (!thisFolder.Exists)
{
thisFolder.Create();
}
strunFilepath = "~/Resources/" + FolderName + "/" + uncFileName;
}
oHttpPostedFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + strunFilepath.Replace("~", ""));
}
string insquery = "INSERT INTO PHOTOS_TABLE(PhotoTitle,PhotoPath,PostedDate) VALUES ('" + txtPhotoTitle.Text + "','" + strcFilepath + "','" + DateTime.Now.ToLongDateString() + "')";
string result = belObj.Recordinsert(insquery);
if (result == "Success")
Page.ClientScript.RegisterStartupScript(this.GetType(), "aaa", "<script language='javascript'>fnalert('Photo Uploaded successfully.')</script>");
}
catch (Exception ex)
{
}
}