2012-12-28 97 views
0
private void BtnInsert_Click(object sender, EventArgs e) 
{ 
     { 


      string strDir = "http://200.100.0.50/chandu/abc.txt"; 
      if (!File.Exists(strDir)) 
      { 
       File.Create(strDir); 
      } 
     } 
} 

我插入的形式记录将被保存在驱动器C服务器:但得到URI格式不正确的格式错误。如何从客户端访问一个文件到服务器

回答

2

那是因为你需要使用UNC路径,如:如果目标支持WebDAV的

\\200.100.0.50\chandu\abc.txt 
+0

的 “http:\\ 200.100.0.50 \ chandu \的abc.txt” 我给了这样再次无法识别逃生误差正在添加 – user1918410

+0

@ user1918410尝试'字符串strDir = @“\\ 200.100.0.50 \ chandu \ ABC .TXT“'。你没有正确地逃避反斜杠。 – Lander

+0

URI格式不受支持 – user1918410

0

你可以把它映射网络驱动器,或直接访问它,但你仍然需要做\ 200.100。 0.5 \无论

0

使用\而不是/

在一个稍微不相关的说明(希望我理解你的问题):

您应该创建一个WebClient并使用DownloadString函数。如果文件存在,该函数将抛出404异常。

WebClient client = new WebClient(); 
client.DownloadString("www.google.com"); // Will work 
client.DownloadString("www.asdfawioeufje.com/awefoasdfasdf"); // 404 error 

正如你所看到的,这可能是做什么我想你想要做的更好的方法。

+0

对不起,我使用Windows感谢您的答案 – user1918410

+0

为什么这不工作,如果你使用Windows?我很困惑。 – AVP

1

使用WebRequest,那么你就有能力发送HTTP HEAD请求。当您发出请求时,您应该得到一个错误(如果文件丢失)或WebResponse与有效的ContentLength属性。

WebRequest request = WebRequest.Create(new Uri("http://www.example.com/")); 
request.Method = "HEAD"; 
WebResponse response = request.GetResponse(); 
Console.WriteLine("{0} {1}", response.ContentLength, response.ContentType); 
+0

我正在使用Windows应用程序,上面的代码将在Windows中工作 – user1918410

相关问题