Wednesday, October 31, 2007

To Upload Documents in C#

if (Charge_To == "CISCO")
{
if((Upload.PostedFile != null)&& (Upload.PostedFile.ContentLength > 0))
{
strFile_Name=Upload.PostedFile.FileName;
strFile_Extn=System.IO.Path.GetExtension(strFile_Name);
File_Name = IE_ID + strFile_Extn;
upload_loc = Server.MapPath("Upload") + "...." + File_Name; //@"http://localhost/PurchaseOrder/Upload/";
Web_loc = ConfigurationSettings.AppSettings["FilePath"].ToString() + File_Name;
try
{
Upload.PostedFile.SaveAs(upload_loc);
//Response.Write("The File has been uploaded");
}
catch(Exception ex)
{
Response.Write("Error: " + ex.Message);
}
StringBuilder buildUpload=new StringBuilder();
buildUpload.Append("insert into PO_Upload values('"+IE_ID+"','"+File_Name+"','"+Requested_by+"','"+Requested_Date+"','"+Web_loc+"')");
SqlCommand sqlcmdUpload=new SqlCommand(buildUpload.ToString(),sqlcon_save);
sqlcmdUpload.ExecuteNonQuery();
}
}

No comments: