views:

51

answers:

3

Hey,

I have a C# client which once every hour needs to post some zip files to ASP.Net site. This needs to be completely automated with no user interaction.

Wondering the best way to go about it.

Ideally would like to post the file without setting up any non .aspx / .asp pages.

Thanks for the help!

+4  A: 

It depends on what the target site expects as content type. If it is multipart/form-data then a simple WebClient should do the job:

using (var client = new WebClient())
{
    byte[] result = client.UploadFile(
        "http://foo.com/index.aspx", @"d:\foo\bar.zip"
    );
    // TODO: Handle the server response if necessary
}
Darin Dimitrov
okay great, hitting the server perfectly however how do I then save the System.Web.MultipartContentElement in ASP (its in the Request)
nextgenneo
Request.SaveAs("C:\\TestFile.zip", false);
nextgenneo
A: 

Send a HttpRequest containing all the necessary information including the bytes of the file. Google should help you on this one.

Nevertheless, I don't understand why you don't want to use a non .aspx page for this. A generic handle (.ashx) is suitable for this. But I still suggest you use another way to upload that file, e.g. per FTP and use a service that watches the directoy with a FileWatcher to determine and act on changes

citronas
Why deal with the file system security set-up for FTP, and then add a new service to watch the directory, (and perhaps having to care about the name of the file) and then install that service, when it's a ten-minute job in the ASPX?
Jon Hanna
A: 

In order to automate the task, you can use a DispatcherTimer (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx), assigning a handler to the Tick event.

jelbourn