Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this code for upload with ftp:
C#
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

        string ftpServerIP = "*";
        string ftpUserName = "*";
        string ftpPassword = "*";
        FileInfo objFile = new FileInfo(filename);
        FtpWebRequest objFTPRequest;
        objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + objFile.Name));
        objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword);

       objFTPRequest.KeepAlive = false;
        objFTPRequest.UseBinary = true;
        objFTPRequest.ContentLength = objFile.Length;
        objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;

        int intBufferLength = 16 * 1024;
        byte[] objBuffer = new byte[intBufferLength];
        FileStream objFileStream = objFile.OpenRead();
        try
        {
            Stream objStream = objFTPRequest.GetRequestStream();
            int len = 0;
            while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
            {
                objStream.Write(objBuffer, 0, len);
            }
            objStream.Close();
            objFileStream.Close();
            Console.Write("File upload success...");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

my error :
System.IO.FileNotFoundException: Could not find file '...'.
Posted
Comments
TrushnaK 15-Jan-14 7:42am    
have you used fileupload in updatepanel.

1 solution

Replace the following

string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

with

string filename = FileUpload1.PostedFile.FileName.ToString();
 
Share this answer
 
Comments
Member 10749235 7-Nov-15 4:21am    
i am using of this line
string filename = FileUpload1.PostedFile.FileName.ToString();
but still getting error.
Could not find file
Member 10749235 7-Nov-15 4:22am    
any one can help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900