Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have the following error "The given path's format is not supported." in File.copy
Below is the code. Pls help me.

C#
string sHostName1 = Dns.GetHostName();
                    IPHostEntry ipE1 = Dns.GetHostEntry(sHostName);
                    IPAddress[] IpA1 = ipE.AddressList;
                    for (int i = 0; i < IpA.Length; i++)
                    {
                        lbl_system.Text = IpA1[i].ToString();


                    }

                   // lbl_system.Text = sp;





                    // string s3 = "\\\\" + sp + "/B1/" + fileName + "";
                    // s3 =  "\\\\"+sp + p + fileName + "";
                    s3 = "\\\\" +IpA1[0] + p + fileName + "";
                    // s3 ="\\E:\s\file";
                    //s3="\\"+
                    System.IO.File.Copy(fileName, s3);//Error

                    // }

                    MessageBox.Show("Files saved");

                }
Posted

1 solution

Try to use Path.Combine(). This will return the path as a string.

C#
s3 = System.IO.Path.Combine(IpA1[0].ToString() , p.ToString() , fileName);


It takes as many as arguments of the type string.

As OP is telling he is getting error, So below code will work for you.
C#
s3 = System.IO.Path.Combine(System.IO.Path.Combine(IpA1[0].ToString() , p.ToString()) , fileName);
 
Share this answer
 
v3
Comments
Prabhu92 13-Mar-15 4:08am    
"No overload for method 'combine' takes 3 argument" I am getting this error
s3 = System.IO.Path.Combine(IpA1[0] , p , fileName);
Prabhu92 13-Mar-15 8:41am    
Still getting the same ERROR "No overload for method 'combine' takes 3 argument"
Praveen Kumar Upadhyay 16-Mar-15 1:53am    
Which framework version you are using of .net
Prabhu92 16-Mar-15 3:07am    
v4.5.1
Praveen Kumar Upadhyay 16-Mar-15 3:28am    
In .Net 4.0, Path.Cobine takes n number of argument. It's declaration is Path.Combine(params string[] paths). I don't know why it is giving error in 4.5. I don't have this version, otherwise could have checked.

If you getting error with 4.5 then check my altered aolution for you.

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