• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

Upload file via ASP.NET to Network Share Drive - USERNAME AND PASSWORD REQ

What I am trying to do is upload a file from the local computer onto a network share drive.
I am not quite sure how to add a Username/Password to my code below... I've taken the code from here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuihtmlcontrolshtmlinputfileclasstopic.asp

Can anyone help?

Thanks in advance....

HTML
--------------------------------------------------
Select File to Upload: <input id="File1" type="file" name="File1" runat="server">
                        
<p>Save as filename (no path): <input id="Text1" type="text" name="Text1" runat="server">
<p><span id="Span1" style="FONT: 8pt verdana" runat="server"></span>
<p><input id="btnUpload" type="button" value="Upload" name="btnUpload" runat="server">

VB.NET SCRIPT
----------------------------------------------------------
Private Sub btnUpload_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.ServerClick
        If Text1.Value = "" Then
            Span1.InnerHtml = "Error: you must enter a file name"
            Return
        End If

        If Not (File1.PostedFile Is Nothing) Then
            Try
                File1.PostedFile.SaveAs(("\\{server}\{Directory}\" & Text1.Value))
                Span1.InnerHtml = "File uploaded successfully to the <b>server as " & _
                                  Text1.Value & "</b> on the Web server"
            Catch exc As Exception
                Span1.InnerHtml = "Error saving file to the <b>Server as " & _
                                  Text1.Value & "</b><br>" & exc.ToString()
            End Try
        End If

    End Sub
0
maidstone
Asked:
maidstone
  • 3
  • 2
1 Solution
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
There are a couple of ways to do this:

1) is to have the user that is in the Application Pool identity be a user that can auto pass through in authentication because the same user exists on the network machine you are connecting to.  
2) You can Create a Windows Identity principal and use the username and password and then impersonate and save. This is the more intensive one because there are ramifications that you need to make sure that you protect yourself from and this is also the slowest because it involves authentication of each request.

Does this make sense?
0
 
maidstoneAuthor Commented:
I dont think I quite understand either...
0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
They both have to do with a Windows Web Server.

So if you are wanting to put a file somewhere where the servers are connected, the only way to save a file somewhere is to have a Username/Password that has access to the place.

So in Web Server land there are 2 places.  1 is the Application Pool Identity that is set in Internet Services Manager on the web server, and the other one is to authenticate via code and use the Username and Password (to create a Windows Principal) and then save the file.

The first one is more common because the Windows Principal concept for something like this is way overkill and more complex.

Does that help?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
maidstoneAuthor Commented:
What you are saying makes no sence to me....
What I did was just put a entry into my Web.Config file....

<identity impersonate="true" userName="{Username}"
password="{Password}" />

I don't think thats the solution you were trying to get accross to me, so I went a different direction.
0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
Whatever the recommendation or protocol is works for me.

Ben.
0
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now