Shaitan00
01-31-2005, 04: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?)
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?)