views:

415

answers:

2

I have very little experience in ASP.NET, so sorry for maybe easy question.

I need to upload a file from a WinForms application to a server, where the file will be automatically processed and saved to a database, without any other user interaction on the server.

I don't have any physical server, all will run on a shared webhosting with ASP.NET in Medium Trust enviroment.

What do I need to have running on the web server? Is it a WebService? I simply don't know where to start and what to look for.

I understand how it could be done with user's interaction:

  1. User goes to our web pages
  2. Click on "Upload" button
  3. Select the file on a hard drive
  4. Click OK, I will catch this event in ASP.NET, upload the file and save it to the database.

When there will be no web page and no user interaction, I have no events on the server that I could use to receive the file and save it on the server.

Perhaps this is an easy task, but I just have no experience with this.

Thanks for all comments, Petr

+1  A: 

I can see 2 options:

  1. Create a WebService on the web server that can be consumed by your WinWorms application.
  2. Post the file (as multipart form) info using poor HTTP protocol from WinForms to your handler on a web server (better ASP.NET MVC).

For me XML Web service would be much easier.

Here is a some info about working with Web Services in Visual Studio.

If you still want to go with approach #2 then you need to use WebRequest class. Here is a sample: Send data using WebRequest.

Dmytrii Nagirniak
Thanks, the Web Service seems to be the right thing I need. Will the Web Service run in Medium Trust enviroment used by common web hostings?
Yes. It will. I do not see reason why not.
Dmytrii Nagirniak
A: 

I think your question comes with an idea of executing a code segment which attaches a file into your database.

Since your server has no user interaction within,your only choice is to call a Web Service after you upload a file from your windows application.

I assume you are using SQL Server ,so you must declare a static path of files (a folder name is enough)where your web-server is stored,then with Server.MapPath(path) method,you can bring absolute path of your file. After having you file Path,you should use System.IO classes: FileStream and StreamReader read file and convert it into a byte[] array,then store it into your database.

Hope this helps

Myra