P
Philip Townsend
I am having difficulties implementing a file uploader. Code is posted
below. The txtFile control contains nothing when submitted, but the
click event is definitely firing the appropriate method. Can any body
help?
protected System.Web.UI.HtmlControls.HtmlInputFile txtFile;
protected System.Web.UI.HtmlControls.HtmlInputButton cmdUpload;
public void uploadFile(object sender, EventArgs args)
{
if(txtFile.PostedFile!=null)
{
String strQFile=txtFile.PostedFile.FileName.ToString();
String strFile=strQFile.Substring(strQFile.LastIndexOf(@"\")+1);
String strFileType=txtFile.PostedFile.ContentType;
int fileSize=txtFile.PostedFile.ContentLength;
// validate the file length
if(fileSize<=0)
{
Response.Write(String.Format(
"<font color=\"red\">Uploading of {0} failed: File is zero
length</font>"));
}
// upload the file
else
{
txtFile.PostedFile.SaveAs(Server.MapPath(@"images/fader/" +
strFile));
Response.Write(String.Format(
"<font color=\"red\">File: {0} successfully uploaded!</font>"));
}
}
else
Response.Write("<font color=\"red\">File is null</font>");
}
private void Page_Load(object sender, System.EventArgs e)
{
txtFile.Accept="text/*";
}
below. The txtFile control contains nothing when submitted, but the
click event is definitely firing the appropriate method. Can any body
help?
protected System.Web.UI.HtmlControls.HtmlInputFile txtFile;
protected System.Web.UI.HtmlControls.HtmlInputButton cmdUpload;
public void uploadFile(object sender, EventArgs args)
{
if(txtFile.PostedFile!=null)
{
String strQFile=txtFile.PostedFile.FileName.ToString();
String strFile=strQFile.Substring(strQFile.LastIndexOf(@"\")+1);
String strFileType=txtFile.PostedFile.ContentType;
int fileSize=txtFile.PostedFile.ContentLength;
// validate the file length
if(fileSize<=0)
{
Response.Write(String.Format(
"<font color=\"red\">Uploading of {0} failed: File is zero
length</font>"));
}
// upload the file
else
{
txtFile.PostedFile.SaveAs(Server.MapPath(@"images/fader/" +
strFile));
Response.Write(String.Format(
"<font color=\"red\">File: {0} successfully uploaded!</font>"));
}
}
else
Response.Write("<font color=\"red\">File is null</font>");
}
private void Page_Load(object sender, System.EventArgs e)
{
txtFile.Accept="text/*";
}