开发者

Uploading a file from a C# desktop application to a PHP script?

开发者 https://www.devze.com 2023-04-06 16:10 出处:网络
I am looking to create a desktop application in C# which : Allows the user to select a file / multiple files / folder containing files from his computer.

I am looking to create a desktop application in C# which :

  1. Allows the user to select a file / multiple files / folder containing files from his computer.
  2. Upload the files selected to a PHP script (which is already equipped to handle file uploads using the $_FILES array.)

I'开发者_运维技巧m a PHP developer and have never coded a single line of .NET before. So, you can assume I have no experience with .NET whatsoever.

I have looked this up online and all I seem to come up with are ASP.NET server side upload controls which i do not want. I'm looking for a client side solution. Also, will i have to make any changes in my PHP script ? The script already handles uploads from an HTML multipart form.

If anyone can help me point in the right direction of where to look, what C# controls are available which can help me create the application I need, I would really appreciate it.


The first, and simplest, way to go about this is to use any of the WebClient's UploadFile methods.

Here's some info an an example;

http://msdn.microsoft.com/en-us/library/36s52zhs.aspx

I have a feeling that this will not be enough for you, since you want to upload multiple files in a single request. The WebClient class can be used to manually build a http multipart request, which is probably your best bet.

It's a bit much to explain how to achieve this here on SO, but there are good guides out there.

Here are a couple of very to-the-point articles

http://www.codeproject.com/KB/cs/uploadfileex.aspx

http://www.codeproject.com/KB/IP/multipart_request_C_.aspx

And if you're interested in the details, or better OO design, here's an alternative (a bit harder to follow if you're not experienced with C#)

http://ferozedaud.blogspot.com/2010/03/multipart-form-upload-helper.html

I think both articles should give you enough info to get started.

0

精彩评论

暂无评论...
验证码 换一张
取 消