Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: ASP.Net File Uploads


Message #1 by "Jonas Bush" <jdbush4@c...> on Tue, 23 Jul 2002 22:39:09
No, I needed the correct enctype attribute in my <FORM> tag...whoops! :D

> I've been trying to upload files with the HtmlInputFile control, 
a> nd I keep getting an "Object reference not set to an 
i> nstance of an object." error, when calling 
U> serFile.PostedFile.SaveAs()...code is as follows:

> 
<> INPUT id="UserFile" type="file" runat="server">

> (and later...)

> <input class="InputButton" id="btnUpload2" type="submit" value="Upload" 
r> unat="server">

> In my codebehind, I have the following:

> this.btnUpload2.ServerClick += new System.EventHandler
(> this.btnUpload2_ServerClick);

> private void btnUpload2_ServerClick(object sender, System.EventArgs e)
{> 
i> f(!ValidatePage())
r> eturn;
s> tring UploadPath = strServerPath + @"\Uploads\" + 
U> serID.ToString() + @"\";
i> f(!Directory.Exists(UploadPath))
{> 
D> irectory.CreateDirectory(UploadPath);
}> 
s> tring strClPath = UserFile.Value; 
s> tring strFileName = strClPath.Substring((strClPath.LastIndexOf(@"\")
+1));
U> ploadPath += strFileName; 
U> serFile.PostedFile.SaveAs(UploadPath); 
}> 

> Anyone have any suggestions?  Thanks...

> Jonas

  Return to Index