How to: Upload a File in ASP.NET
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: How to: Upload a File in ASP.NET
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: How to: Upload a File in ASP.NET
Join the conversation! Your thoughts help the community grow.
Join to leave a comment
Members earn 10 SHARP for a comment, 10 SHARP for a reaction, and 1,000 SHARP for every article they publish.
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegisterMembers onlyeBook · ASP.NETASP.NET Tags in Web Forms: The Complete GuideDownload nowWrite an article and earn +1,000 SHARP when it is approved.
Write an article
Deven ThakurPosted Apr 2, 2011, 1:07 AM EDT
after saving the file .. we saved its address as a database field.... ok but how we will access that file at the front with the use of that address stored in database plz plz solve my query....
bhargav reddyPosted Aug 16, 2010, 10:08 PM EDT
Hi, This very nice article.
Ruan jingbiaoPosted Jul 20, 2010, 11:55 PM EDT
there some codes: string fileName =pdf.FileName;//????? if (fileName != null)//???? { string postfix = System.IO.Path.GetExtension(fileName).ToString().ToLower();//????? if (postfix == ".pdf" || postfix == ".rar" || postfix == ".doc" || postfix == ".jpg" || postfix == ".txt" || postfix == ".gif" || postfix == ".bmp" || postfix == ".xls") { double size = pdf.FileContent.Length / 1024; if (size <= 5120) { Regex reg = new Regex(@"\.\w*?$"); string path = ""; string reFileName = reg.Replace(fileName, "") + DateTime.Now.ToStr("yyyyMMdd") + DateTime.Now.Ticks + postfix; string companyName = TSQL.ExecDr(this.getSQL("selectcompanybyId"), Session["CompanyID"].ToInt32())["com_name"].ToStr();// TSQL.ExecuteScalar(this.getSQL("selectcompanynamebyId"), Session["CompanyID"].ToInt32()).ToStr(); string foo = Server.MapPath("..//Js"); string folder = Server.MapPath("..//PdfFile") + "\\" + companyName; if (Directory.Exists(folder)) path = folder + "\\" + reFileName.ToStr(); else { Directory.CreateDirectory(folder); path = folder + "\\" + reFileName.ToStr(); } pdf.SaveAs(path); files = "../PdfFile/" + companyName + "/" + reFileName; if (this.HiddenField1.Value == "") TSQL.ExecuteNonQuery(this.getSQL("insertintockmt"), no.Text.ToStr(), name.Text.ToStr(), style.Text.ToStr(), date.Text.ToDateTime(), price.Text.ToDecimal(), power.Text.ToDecimal(), heigth.Text.ToDecimal(), width.Text.ToDecimal(), length.Text.ToDecimal(), weigth.Text.ToDecimal(), provider.Text.ToStr(), works.Text.ToStr(), Session["CompanyID"].ToInt32(), files); else { if (pdfs.Value == "") TSQL.ExecuteNonQuery(this.getSQL("updateckmt"), no.Text.ToStr(), name.Text.ToStr(), style.Text.ToStr(), date.Text.ToDateTime(), price.Text.ToDecimal(), power.Text.ToDecimal(), heigth.Text.ToDecimal(), width.Text.ToDecimal(), length.Text.ToDecimal(), weigth.Text.ToDecimal(), provider.Text.ToStr(), works.Text.ToStr(), files, this.HiddenField1.Value.ToInt32(), Session["CompanyID"].ToInt32()); else TSQL.ExecuteNonQuery(this.getSQL("updateckmt"), no.Text.ToStr(), name.Text.ToStr(), style.Text.ToStr(), date.Text.ToDateTime(), price.Text.ToDecimal(), power.Text.ToDecimal(), heigth.Text.ToDecimal(), width.Text.ToDecimal(), length.Text.ToDecimal(), weigth.Text.ToDecimal(), provider.Text.ToStr(), works.Text.ToStr(), pdfs.Value.ToStr(), this.HiddenField1.Value.ToInt32(), Session["CompanyID"].ToInt32()); this.HiddenField1.Value = ""; } } } else this.ScriptManager1.alert("????pdf??,doc??,xls??,txt??,jpg??,gif??,bmp??,rar????"); i use fileupload control , but can't upload pdf files why...? if you can help me , please send email for [email protected] thinks...
Farid EkhteraeiPosted Jun 17, 2010, 11:56 PM EDT
Thank you for your useful code. Works great.
ruby guptaPosted Apr 23, 2010, 10:09 PM EDT
hi....could you help me to store files in database(sql server2005) using file upload tool.
sarav kannaneditedPosted Oct 9, 2009, 9:01 PM EDTEdited Oct 9, 2009, 9:05 PM EDT
http://www.onlineatoz.net/onlineatoznet/forum/post/ToolBox-Standard-Control-FileUpload.aspx
Ram Narain prajapatiPosted Apr 14, 2009, 1:17 AM EDT
nice source for file upload congrates for this
zenny kkPosted Apr 7, 2009, 10:45 PM EDT
i am able to upload the file.. now i hav to modify the file and save again in the oracle databse.. modify is not happening.... can any1 help?
mohammed subaaPosted Apr 6, 2009, 12:27 PM EDT
thanks more
zenny kkPosted Apr 6, 2009, 4:06 AM EDT
hiii the code u hav posted is of real good help.... im a student in a college and trying to learn asp.net. there is nobody to help. could i get ur help or any contact plz plz plz plz plz plz plz...
Ashish RPosted Jan 3, 2009, 8:20 AM EST
how to assign a text in Text Box of UpLoadFile Control in ASP.Net
reer dgdgdPosted Dec 30, 2008, 12:55 AM EST
another example here : http://www.mo8.co.il/WebControls.aspx
satya anand andraPosted Dec 16, 2007, 10:51 PM EST
your program is working great..... could you plz tell me.. How to save the file as it is in the same format as in the previous....
Etienne PennekanPosted Nov 22, 2007, 10:33 PM EST
Hi Great......it works but i cant upload a LARGE file.... Why is that? Etienne
Michael SaulPosted Oct 17, 2007, 4:35 AM EDT
How could I maintain the original file's timestamps, etc.? Using File.Copy() method works locally, but I need that on the web server...
P KarthickPosted Aug 2, 2007, 10:55 PM EDT
Hi Rahul, This is nice one keep upload some more applications Cheers, Karthick