Solved

How can I build an ASP.NET site to catch files from Computer.Network.UploadFile

Posted on 2014-08-01
7
200 Views
Last Modified: 2014-09-10
I have a Windows app that uses Computer.Network.UploadFile to FTP files to our servers.  I want to start using HTTPS rather than FTP.  According to MS here (http://msdn.microsoft.com/en-us/library/dfkdh7eb(v=vs.90).aspx) this is possible but they never explain how.  They reference 'upload.aspx' but I can't find any information on what this site needs to include.  I need this to be a protected site so the UN and PW field will be included in the Computer.Network.UploadFile call.
0
Comment
Question by:RobertBroach
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40236196
Here is an example of an .aspx that can accept uploaded files (if that is what you are looking for):

WebClient.UploadFile Method (String, String, String)
http://msdn.microsoft.com/en-us/library/vstudio/esst63h0(v=vs.100).aspx

<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>

<Script language="VB" runat=server>
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim f As String
        Dim file
        For Each f In Request.Files.AllKeys
            file = Request.Files(f)
            file.SaveAs("c:\inetpub\test\UploadedFiles\" & file.FileName)
        Next f

    End Sub

</Script>
<html>
<body>
<p> Upload complete. </p>
</body>
</html>

Open in new window

0
 

Author Comment

by:RobertBroach
ID: 40239258
Bob,

Thanks for the reply.  This looks very promising but I don't see how to use the UN and PW to upload to a password protected site (standard authentication using Active Directory) with WebClient.UploadFile.  Does this only allow uploads to public sites?

With Computer.Network.UploadFile and FTP we just include the UN and PW and it works great.  MS implies here(http://msdn.microsoft.com/en-us/library/w3kksch7(v=vs.90).aspx) that it can be done.

Todd
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40239292
Please refresh my memory on how you use FTP to pass those fields, please.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:RobertBroach
ID: 40239324
Bob,

The Computer.Network.UploadFile method (http://msdn.microsoft.com/en-us/library/dfkdh7eb(v=vs.90).aspx) has UN and PW parameters.  The MSDN page says that the address parameter can use either the FTP or HTTP protocol.  We have been using this method in our Windows app to FTP files from clients computers to our servers for almost 10 years.  We want to add the option to use HTTPS because we have some corporate environments where we have trouble with FTP (firewalls, ports, antivirus software...).  We also want to switch to HTTPS to protect our clients UNs and PWs when transmitted over the internet.

Todd
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40239355
Do you mean "user name" and "password" parameters?  If so, then you can pass encrypted arguments in the query string parameters to the web page, and check those values on the web site side with the Request.QueryString collection.

P.S. Here is some good reading about "clarity" and "brevity":  

Brevity and Clarity
http://blogvault.net/brevity-and-clarity/

Clarity and brevity go hand in hand. It’s sometimes tempting to sacrifice one for the other but that is a slippery path to walk on.  You cannot skip essential details and assume that your reader knows everything. Brevity is part of clarity; some even say that it is the soul of clarity. Aren’t both one and the same, you may ask? Not quite! You can be brief and unclear or clear and verbose! The magic mantra is to be clear and brief at the same time.

I find acronyms to be brief and unclear.
0
 

Author Comment

by:RobertBroach
ID: 40239441
Bob,

UN = 'userName'
PW = 'password'

I am trying to use the Computer.Network.UploadFile method that is used in our current application that is installed on close to 100 client's computers.  I can't change that as it is not practical for me to re-install all of those current installations.  If I can figure out how to build the 'upload.aspx' page that is referred to in the MSDN article (including the user credentials) then it is a solution that I can make work.

Todd
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40239608
Here is an example that you can use in upload.aspx, referencing query string parameters:

 Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim userName As String = Request.QueryString("userName")
        Dim password As String = DecryptPassword(Request.QueryString("password"))

        If Not ValidateLogin(userName, password) Then Return

        Dim f As String
        Dim file
        For Each f In Request.Files.AllKeys
            file = Request.Files(f)
            file.SaveAs("c:\inetpub\test\UploadedFiles\" & file.FileName)
        Next f

    End Sub

Open in new window


URL example:
My.Computer.Network.UploadFile ( "C:\My Documents\Order.txt", "http://www.cohowinery.com/upload.aspx?userName=Bob&password=ADEE3D03AE")
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Output Caching in IIS 2 28
SqlServer no dupes 25 34
Help with adding DLL file in Windows project 20 28
Create a datatable in vb.net dynamically 1 12
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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