protected void Button2_Click(object sender, EventArgs e) { if (MyFile.PostedFile != null) { HttpPostedFile uploadFile = MyFile.PostedFile; if (System.IO.Path.GetExtension(uploadFile.FileName).ToLower() == ".jpg") { string strFileName = Path.GetFileName(uploadFile.FileName); FileInfo fileInf = new FileInfo(strFileName); FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://111.111.113./httpdocs/uploadpic/" + fileInf.Name)); reqFTP.Method = WebRequestMethods.Ftp.UploadFile; reqFTP.Credentials = new NetworkCredential("music", "123"); reqFTP.KeepAlive = true; reqFTP.UseBinary = true; Stream ftpStream = reqFTP.GetRequestStream(); FileStream file = fileInf.OpenRead(); int length = 1024; byte[] buffer = new byte[length]; int bytesread = 0; do { bytesread = file.Read(buffer, 0, length); ftpStream.Write(buffer, 0, bytesread); } while (bytesread != 0); file.Close(); ftpStream.Close(); } }
Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\IMG_6391.JPG'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\IMG_6391.JPG'. Source Error: Line 108: Line 109: Stream ftpStream = reqFTP.GetRequestStream(); Line 110: ** FileStream file = fileInf.OpenRead(); Line 111: Line 112:
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)