| | |
file upload
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
HI,
Add fileupload control in your page. Then
Add fileupload control in your page. Then
c# Syntax (Toggle Plain Text)
if (null != file.PostedFile) { try { if (file.ContentType.IndexOf("excel") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Excel\" + filename)); else if (file.ContentType.IndexOf("word") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Word\" + filename)); else file.SaveAs(Server.MapPath(@"\Upload\Other\" + filename)); } catch (Exception e) { } }
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Now I tryed that, but it didn't work.
Under: filename a red line appears, and if I hold the mouse on that it writes: The name 'filename' does not exist in the current context.
and under ContentType a red line also appears witch says:
'System.web.ui.webcontrols.Fileupload' does not contain a definition for 'contenttype' and no extension method 'contenttype' accepting a first argument of type
'System.web.ui.webcontrols.Fileupload' could be found (are you missing a using directive or an assembly refference?)
Do you know how to fix it? please?
my whole code on my cs page looks like this:
Under: filename a red line appears, and if I hold the mouse on that it writes: The name 'filename' does not exist in the current context.
and under ContentType a red line also appears witch says:
'System.web.ui.webcontrols.Fileupload' does not contain a definition for 'contenttype' and no extension method 'contenttype' accepting a first argument of type
'System.web.ui.webcontrols.Fileupload' could be found (are you missing a using directive or an assembly refference?)
Do you know how to fix it? please?
my whole code on my cs page looks like this:
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Collections; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (null != file.PostedFile) { try { if (file.ContentType.IndexOf("excel") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Excel\" + filename)); else if (file.ContentType.IndexOf("word") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Word\" + filename)); else file.SaveAs(Server.MapPath(@"\Upload\Other\" + filename)); } catch (Exception e) { } } } }
Last edited by peter_budo; Apr 15th, 2009 at 7:57 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags. Keep It Spam-Free Do not spam, advertise, plug your website.
Replace filename by
ALSO REPLACE file.ContentType BY
Also makesure that you have cretaed a folder named Upload in root & also create another 3 folders named Excel,Word,Other as subfolder.
ASP.NET Syntax (Toggle Plain Text)
file.PostedFile.FileName
ALSO REPLACE file.ContentType BY
ASP.NET Syntax (Toggle Plain Text)
file.PostedFile.ContentType
Also makesure that you have cretaed a folder named Upload in root & also create another 3 folders named Excel,Word,Other as subfolder.
Last edited by mail2saion; Apr 13th, 2009 at 3:23 pm. Reason: Missed few points to reply
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Now I've tried to test my code, but it doesn't seem to save the files in the folders iv'e created.
But it doesn't write any errors, it just doesn't save the files.
all my code now looks like this on the cs page:
and on the aspx page:
do you know what the problem can be?
Thanks.
But it doesn't write any errors, it just doesn't save the files.
all my code now looks like this on the cs page:
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Collections; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void upload_Click(object sender, EventArgs e) { if (null != file.PostedFile) { try { if (file.PostedFile.ContentType.IndexOf("excel") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Excel\" + file.PostedFile.FileName)); else if (file.PostedFile.ContentType.IndexOf("word") >= 0) file.SaveAs(Server.MapPath(@"\Upload\Word\" + file.PostedFile.FileName)); else file.SaveAs(Server.MapPath(@"\Upload\Other\" + file.PostedFile.FileName)); } catch (Exception) { } } } }
and on the aspx page:
ASP.NET Syntax (Toggle Plain Text)
<asp:FileUpload ID="file" runat="server" /><br /> <asp:Button ID="upload" runat="server" Text="upload" onclick="upload_Click"/>
do you know what the problem can be?
Thanks.
Yes the problem is iis user cant write to the upload folder. Means its permission isue. Right click on upload folder which you cretated in your root folder then click properties then click on security tab then add then Write everyone click on checkname & finaly ok.
If problem doesnot resolved yet then print the exception from catch block & post the error into this thread.
If problem resolved then remove everyone permission from upload folder & give the permission to iis default user.
If problem doesnot resolved yet then print the exception from catch block & post the error into this thread.
If problem resolved then remove everyone permission from upload folder & give the permission to iis default user.
Last edited by mail2saion; Apr 13th, 2009 at 5:24 pm. Reason: Missed to append few lines
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Similar Threads
- File Upload Help (PHP)
- File upload problem (PHP)
- Need file upload code for word Doc (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: login+ Contol panel.aspx
- Next Thread: Textbox is not losing its previous value
| Thread Tools | Search this Thread |
.net 3.5 activexcontrol ajax alltypeofvideos appliances asp asp.net bc30451 beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox login microsoft mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





