user1918410
user1918410

Reputation: 69

How to access a file from a client to a server

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

I am inserting records in form that will be stored in the server in drive C: but get URI format was not in the correct format error.

Upvotes: 0

Views: 115

Answers (4)

sajanyamaha
sajanyamaha

Reputation: 3198

Use WebRequest, then you gain the ability to send an HTTP HEAD request. When you issue the request, you should either get an error (if the file is missing), or a WebResponse with a valid ContentLength property.

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

Upvotes: 1

AAA
AAA

Reputation: 1384

Use \ instead of /

On a slightly unrelated note (hopefully I understand your question):

You should create a WebClient and use the DownloadString function. The function will throw a 404 exception if the file exists.

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

As you can see, this is probably a better way of doing what I think you want to do.

Upvotes: 0

Crash893
Crash893

Reputation: 11702

if the target supports webdav you can either map it as a network drive or just access it directly but you still need to do \200.100.0.5\whatever

Upvotes: 0

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

That's because you need to use a UNC Path like:

\\200.100.0.50\chandu\abc.txt

Upvotes: 2

Related Questions