...

View Full Version : Upload File to Web-Server



Shaitan00
01-31-2005, 05:12 AM
I have no clue why the following isn't working, maybe someone could take a look.

HTML SOURCE CODE:
<form id="Form1" style="TEXT-ALIGN: center" method="post" encType="multipart/form-data" runat="server">
<INPUT id="fileUpdate" name="fileUpdate" type="file" runat="server"><br>
<INPUT id="subUpdate" name="subUpdate" value="Upload" type="submit" runat="server"><br>
</form>

C# SOURCE CODE:
private void subUpdate_ServerClick(object sender, System.EventArgs e)
{
if( ( fileUpdate.PostedFile != null ) && ( fileUpdate.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(fileUpdate.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;

try
{
fileUpdate.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}

catch ( Exception ex )
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please enter a file to upload.");
}
}

I created a folder called [Data] in my \wwwroot\project folder, I expected the code to take any <4meg file when browsing and upload it to that folder (and post the corresponding message via the Response.Write).

However I find that a) I get no Messages (Response.Write is supposed to display a message no?) and b) the file is not uploaded after pressing the UPLOAD button, the browse box is cleared and the page seems to refresh.. Still no messages.

Any clues? (I am still kind of new at all this ASP stuff)
Could it be like folder permissions? (wouldn't that give me access denied?)

glenngv
01-31-2005, 05:58 AM
I dug this up from my archive, you might want to check out.

Bullschmidt
02-02-2005, 09:40 AM
And here is a pure ASP (i.e. no components) resource for letting the user upload a file which is something that was unfortunately not built into ASP:

ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
http://aspzone.com/posts/160.aspx

Bullschmidt
07-22-2005, 06:27 PM
Updated (corrected) link:

ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
http://aspzone.com/articles/160.aspx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum