Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
hey all, I want to select the items (file) which choose from treeview after that i click button upload, it file will be up to server. I get fail and erorr below:
 
UriFormatException was unhandle Invalid URI: The hostname could not be parsed.
 
Picture demo
http://i1055.photobucket.com/albums/s505/vn_photo/23.jpg[^]
 
Code of function upload
        private void UploadFile(string filename)
        {
            FileInfo fileInfo = new FileInfo(filename);
            string FileAndFolder = "ftp://" + serverIP + "/" + fileInfo.Name;
            FtpWebRequest RequestFTP;
            RequestFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverIP + "/" + fileInfo.Name));
            RequestFTP.Credentials = new NetworkCredential(username, passwd);
            RequestFTP.KeepAlive = false;
            RequestFTP.Method = WebRequestMethods.Ftp.UploadFile;
            RequestFTP.UseBinary = true;
            int sizedata = 1024;
            byte[] data = new byte[sizedata];
            int contlenght;
            FileStream fs = fileInfo.OpenRead();
 
            try
            {
                Stream strm = RequestFTP.GetRequestStream();
                contlenght = fs.Read(data, 0, sizedata);
                while (contlenght != 0)
                {
                    strm.Write(data, 0, contlenght);
                    contlenght = fs.Read(data, 0, sizedata);
                }
                strm.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Upload Fail");
            }
        }
Code of event click button upload
        private void btnUpload_Click(object sender, EventArgs e)
        {
            String fileName = trwFileExplorer.SelectedNode.ToString();
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\");
            System.IO.FileInfo[] files = dir.GetFiles();
            System.Collections.ArrayList arrList = new System.Collections.ArrayList();
            foreach (System.IO.FileInfo f in files)
            {
                fileName = System.IO.Path.GetFullPath(f.Name);
            }  
            MessageBox.Show(fileName);
 
                UploadFile(fileName);
        }
Posted 13-Oct-12 17:47pm
Edited 13-Oct-12 18:23pm
103.7K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 888
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100