tags:

views:

85

answers:

2

Hello,

I work as software tester entry level and I was given a task to save my log files to the specific folder on my company website and this website only can be accessed internally by the company employees. So far I know how to save file onto the site, but how would I check which specific folder is already there before I save the file to it?

    private void SaveLogsTogWeb(string file)
    {
        try
        {
            //create WebClient object
            WebClient client = new WebClient();

            client.Credentials = CredentialCache.DefaultCredentials;

            client.UploadFile(@"http://myCompnay/MyProjects/TestLogs/" + file, "PUT", file);
            client.Dispose();
        }
        catch (Exception err)
        {
            MessageBox.Show(err.Message);
        }
    }

Thanks in advance for the helps

+2  A: 

Use this code:

if(!Directory.Exists({path}))
{
   //create the directory
}

It checks to see if the directory doesn't exist. And if it doesn't then you can create it!

Andrew Siemer
Does that work for URLs?
RedFilter
I tried it, but doesn't work.
Bopha
A: 

One way would be to put a dummy file in that folder (dummy.txt) and do an HTTP GET of the file. If you can successfully do that, you can then assume the folder exists (barring any virtual folders, etc.)

RedFilter
That's a good approach, but I'm not quite sure if my manager wants to have unwanted file in the folder.
Bopha
Well, try doing a GET for http://myCompnay/MyProjects/TestLogs/. There are various responses you may get, including Directory Browsing Not Allowed, but you should eb able to determine from the response whether the folder exists or not.
RedFilter
I will give it try, but it's going to take me while since I don't know what is HTTP GET.. thanks for your suggestion.
Bopha
what namespace should I include in the project to use HTTPGet, because it says it's missing namespace or assembly but from MS website I try Microsoft.Dss.Core.DsspHttp, still it doesn't show.
Bopha
Since I don't know how to use HTTP GET, I just use webclient.download instead to check for dummy file flagging folder existen. thanks.
Bopha