NokX
September 26, 2012, 2:53pm
1
Here’s my form…
<form method="post" enctype="multipart/form-data">
<input type="file" name="filScreenshot" id="filScreenshot" /><br />
<input type="submit" name="btnSubmit" value="Submit" />
</form>
How does my .NET code need to look in order to upload a file? I’ve searched all over, but there seems to be so many ways to do it and none are really working.
Thanks!
GeorgL
September 26, 2012, 9:47pm
2
Where is the backend and button action?
Are you in Visual Studio? it’s C# or VB.Net ?
This code will not work at all.
GeorgL
September 26, 2012, 9:49pm
3
NokX
September 27, 2012, 2:10pm
4
C#. I have all the backend code in place except for the code that takes the selected file from filScreenshot and uploads it to my server.
NokX
September 27, 2012, 3:51pm
5
I’m trying baby steps. What can I use to ensure a file was uploaded? Nothing in those links are working for me.
For example…
Request.Files["filScreenshot"].HasFile
That gives me this error: ‘System.Web.HttpPostedFile’ does not contain a definition for ‘HasFile’
NokX
September 27, 2012, 4:25pm
6
I found something that works. I can take it from here. Thanks!
if (Request.Files.Count > 0) {
HttpPostedFile file = Request.Files[0];
file.SaveAs(Server.MapPath("images/myFile.jpg"));
}
GeorgL
September 28, 2012, 8:31am
7
Download Visual Web Developer at Microsoft. http://www.asp.net/vwd
You should start coding in a visual environmen, with auto complete abilities it’s more easy to do jobs! you are coding like ASP3 Classic in ASP.Net . but everything has changed, You have fundamental problems in your codes.
<form id="form1" runat="server">
<div>
<h2>Upload File</h2>
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click"
Text="Upload" />
<p><asp:Label ID="lblInform" runat="server"></asp:Label></p>
</div>
</form>
hop this helpful
wwb_99
January 8, 2013, 4:01pm
9
That doesn’t – you don’t even have a key attribute on the form to make it post uploaded files.