Am having trouble with some code here to upload a file. The code implies that the upload has always failed as the null value is always executed in one of the first branches of the loop! Help. I have included the cs file below - the html is just a simple form...I just cannot get this to upload. I partially took the code from another source sometime ago and now even after tinkering does not seem to work. Thanks<BR><BR>using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR>using System.IO;<BR><BR><BR><BR><BR>namespace CVUploader<BR>{<BR> /// &#060;summary&#062;<BR> /// Summary description for WebForm1.<BR> /// &#060;/summary&#062;<BR> public class WebForm1 : System.Web.UI.Page<BR> {<BR> private const string MDBFILE = "FileUpload.mdb";<BR> protected System.Web.UI.WebControls.Button Butt_Sub_CV;<BR> protected System.Web.UI.WebControls.Label Lbl_Status;<BR> protected HtmlInputFile FileUpload;<BR> <BR> <BR> public WebForm1()<BR> {<BR> Page.Init += new System.EventHandler(Page_Init);<BR> }<BR><BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> // Put user code to initialize the page here<BR> }<BR><BR> <BR> private void Page_Init(object sender, EventArgs e)<BR> {<BR> //<BR> // CODEGEN: This call is required by the ASP.NET Web Form Designer.<BR> //<BR> InitializeComponent();<BR> }<BR><BR> #region Web Form Designer generated code<BR> /// &#060;summary&#062;<BR> /// Required method for Designer support - do not modify<BR> /// the contents of this method with the code editor.<BR> /// &#060;/summary&#062;<BR> private void InitializeComponent()<BR> { <BR> this.Load += new System.EventHandler(this.Page_Load);<BR><BR> }<BR> #endregion<BR><BR><BR> private void WriteToFile(string strPath, ref byte[] Buffer)<BR> {<BR> // Create a file<BR> FileStream newFile = new FileStream(strPath, FileMode.Create);<BR><BR> // Write data to the file<BR> newFile.Write(Buffer, 0, Buffer.Length);<BR><BR> // Close file<BR> newFile.Close();<BR> }<BR><BR><BR> private void Butt_Sub_CV_Click(object sender, System.EventArgs e)<BR> {<BR> // Check to see if file was uploaded<BR> // Maximum Number of bytes that can be uploaded<BR> long MaxNumberbytes = 35000;<BR> Lbl_Status.Text = "Uploading...";<BR> Lbl_Status.Text = "Value of file: " + FileUpload.ToString();<BR> <BR> if ( FileUpload.PostedFile == null )<BR> {<BR> Lbl_Status.Text = "NULL";<BR> }else<BR> {<BR><BR> Lbl_Status.Text = "NOT NULL";<BR> }<BR><BR> <BR><BR><BR> if ( FileUpload.PostedFile != null )<BR> {<BR> // Get a reference to PostedFile object<BR> HttpPostedFile myFile = FileUpload.PostedFile;<BR> Lbl_Status.Text = "doing it";<BR><BR><BR> // Get size of uploaded file<BR> int nFileLen = myFile.ContentLength; <BR><BR> // Need to check that only extensions are those specified!!<BR> // i.e. .doc and pdf files! Or perhaps text files.<BR> <BR> string strtype = myFile.ContentType.ToString();<BR> Lbl_Status.Text = strtype; <BR> <BR> if (strtype == "application/msword" &#124&#124 strtype == "application/pdf")<BR> {<BR><BR> // make sure the size of the file is &#062; 0<BR> if( nFileLen &#062; 0 && nFileLen &#060; MaxNumberbytes )<BR> {<BR> // Allocate a buffer for reading of the file<BR> byte[] myData = new byte[nFileLen];<BR><BR> // Read uploaded file from the Stream<BR> myFile.InputStream.Read(myData, 0, nFileLen);<BR><BR> // Create a name for the file to store<BR> //string strFilename = Path.GetFileName(myFile.FileName);<BR><BR> // Name the filename with the ID of the user in the table<BR> string strFilename = "primaryID";<BR><BR> // Write data into a file - need to sort out the paths of saving the files!<BR> WriteToFile(Server.MapPath(strFilename), ref myData);<BR><BR> // Store it in database<BR> //int nFileID = WriteToDB(strFilename, myFile.ContentType, ref myData);<BR><BR> Lbl_Status.Text = "Size of file uploaded: " + nFileLen;<BR> // need to affirm status of upload to the database<BR><BR> }<BR> else<BR> {<BR> if (nFileLen &#060;= 0 ) <BR> {<BR> Lbl_Status.Text= "Sorry file is Empty";<BR> }<BR> else<BR> {<BR> Lbl_Status.Text = "Sorry file is larger than " +MaxNumberbytes + "Kb";<BR> }<BR> }<BR><BR> }<BR><BR> else<BR> {<BR> Lbl_Status.Text = "Please upload a Microsoft Word or PDF file.";<BR> }<BR> }<BR> else<BR> {<BR> Lbl_Status.Text = "File is empty - please select a file.";<BR> <BR> }<BR><BR><BR> }<BR> <BR><BR> }<BR>}<BR><BR><BR>