不支持给定路径的格式 [英] The given path's format is not supported

查看:121
本文介绍了不支持给定路径的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有以下错误不支持给定路径的格式。在File.copy中

下面是代码。请帮助我。



Hi I have the following error "The given path's format is not supported." in File.copy
Below is the code. Pls help me.

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");

                }

推荐答案

尝试使用Path.Combine()。这将以字符串形式返回路径。



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

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





需要与字符串类型的参数一样多。



由于OP告诉他收到错误,所以下面的代码对你有效。



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.

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


这篇关于不支持给定路径的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆