Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Windows service for automatic file uploading to web site..

Posted on 2004-09-20
3
331 Views
Last Modified: 2012-05-05
I would like to be able to write a Window's service application that is able to automatically upload files to a web site.  Basically the service will poll a directory for new files to upload to the web.  I have the process of polling for files complete, but I cannot figure out how to upload them in the background.  There is a page on the web site that is simply a form with a text box for the filename and an update button.

I have tried using the AxWebBrowser control, but it does not seem to work from within a service (maybe I am just using it wrong).

Any ideas would be great, Thanks!
0
Comment
Question by:stu_pb
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
ajitanand earned 250 total points
ID: 12109440
hello,

I believe if the web server script is your own(you have control on it), then you dont even need to use any third party software.

The following code (pure .Net) helps you upload a file in just few lines!  The only thing is that you can not control the name of the FormField that is designated to the uploaded file.
(add a refernce to System.Web.dll to your project)

----------------------------------------
Public Sub Upload() 'Much Neat than using the AxWebBrowser!!!
      Dim path As String = "D:\\clientsdata\\genesis\\webs\\accept.asp"
      Dim url As String = "http://localhost/accept.asp"

      Dim client As System.Net.WebClient = New System.Net.WebClient()
      Dim bytes() As Byte = client.UploadFile(url, "POST", path)
      client.Dispose()

      'Examine response to see if upload was successful.
      'this response is the standard HTML output thrown by the web script that is accepting the file upload
      'In my example I assume that the scripts returns "success" if file is uploaded

      Dim response As String = System.Text.Encoding.ASCII.GetString(bytes)
      Console.Out.Write(response)
End Sub
----------------------------------------
This HTML control name "MIGHT" be relevant since the fileupload control in the html form that your script that accepts file upload on the webserver, might expect a specific Name.

for e.g. the following html form uploads a file under the name MyFile:

<form.............>
<input type=file name="MyFile">
<input type=submit>
</form>

And if your script specifically wants the name of the input field to be exactly MyFile then you can not control it through my code above. To make it work, you need to also make sure that your upload script can be made to accept whatever field uploads the file.

------------------------

Regarding AxWebBrowser Control - Make sure that the same problem is not happening with this control as well.

-----------------------

If you can post your upload script + html file that uploads the file on the server, I can check it. If that is fine, we will then check if your webservice is working and configured properly.

-----------------------
Final Note (Tip): usually to add background processes through Services, you need to make the application multithreaded most of the times.

----------------------

Post your inputs over th above comments, and I will reply specific solutions.

warm rgds,
Ajit Anand

0
 
LVL 5

Expert Comment

by:ajitanand
ID: 12109454
One thing!

AxWebBrowser control is something that exposes UI. Mind it that using UI enabled things in Windows Service is not just the right thing. It needs to be something in background! No UI at all anyhow! So AxWebBrowser is not the right way...

If my above .net based solution does not help, you need another UI less code that uploads files through HTTP.

rgds,
Ajit Anand
0
 
LVL 3

Author Comment

by:stu_pb
ID: 12110906
Thanks for your help, this works perfectly for my situation.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expression Evaluater 3 37
SQL Query Help Top 1 and Distinct? 6 35
Where is this file? 3 25
PowerShell:  Column widths won't expand 3 17
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question