Hi,
I'm trying to upload a file and I do that with this code, but there is a
thing which doesn't work. I can't understand how to check if it isn't
written the path to the file(the text field of <input> control is empty) or
it is.
I have tryed with the following:
if( filMyFile.Poste dFile != null) //HtmlInputFile filMyFile;
{
code
}
else
{
code
}
and with:
if(filMyFile.Va lue=="")
{
code
}
else
{
code
}
but everytime( when the text filed with the path is empty or filled) the if
statement works in same way.
How could be checked if the path is filled or it isn't?
Here is my code.Thank you in advance!
private void Button1_Click(o bject sender, System.EventArg s e)
{
msg.Text="";
if(filMyFile.Po stedFile != null)
{
try
{
// Get a reference to PostedFile object
HttpPostedFile myFile = filMyFile.Poste dFile;
// Get size of uploaded file
int nFileLen = myFile.ContentL ength;
if(myFile.Conte ntType.CompareT o("image/gif")==0)
{
// Allocate a buffer for reading of the file
byte[] myData = new byte[nFileLen];
// Read uploaded file from the Stream
myFile.InputStr eam.Read(myData , 0, nFileLen);
string strFilename = Path.GetFileNam e(myFile.FileNa me);
string strDir = "c:\\Inetpub\\w wwroot\\Estates \\Files\\" +
Session["usrName"].ToString();
Directory.Creat eDirectory( strDir);
string
strRoute=MapPat h("/Estates/Files/"+Session["usrName"].ToString()+"/"+strFile
name);
//string strFilename = Path.GetFileNam e(myFile.FileNa me);
//string strRoute=MapPat h("/Estates/Files/"+strFilena me );
WriteToFile(str Route,myData);
msg.Text="The file was attached";
}
else
{
msg.Text="This file is not a gif!!!";
}
}
catch(Exception exc)
{
msg.Text = "Error by saving: " + exc.ToString();
}
}
else
{
msg.Text="Pleas e, atach your file!";
return;
}
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.