Click here to Skip to main content
11,710,472 members (78,095 online)
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
(no name)115.6K
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 549
1 OriginalGriff 270
2 Peter Leow 134
3 Abhinav S 130
4 Richard MacCutchan 80
0 Abhinav S 60
1 Member 4653839 40
2 barneyman 35
3 Sergey Alexandrovich Kryukov 35
4 Member 11793820 35


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2015
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