471,321 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

Multiple File copy to Web Server

Long time reader, first time poster... Any help is appreciated.

I have a few questions regarding Winform controls embedded within an
html page. For more info please see the appendix. Now, for the

1. A button on my control executes the
System.IO.Directory.GetDirectories funtion (the scanned directory
resides on the hosting web server). What credentials is this
accomplished with from the client machine, the users windows login or
a .NET machine account? Can these credentials be changed (kind of like
an impersonate in ASP.NET)?

2. I have a button on my control that executes the System.IO.File.Copy
method (again the "copy to" directory resides on the hosting web
server). Same questions as above regarding credentials...

3. Ideally I would like to authentice the user and then execute the
remainder of the controls file functions under the identity of a
specific AD account (one such that the users do not even know exits).
Is this possible?

Please keep in mind this all executes on the client machine and does
not utilize ASP.Net.

The Original Problem:
1. Copy multiple html, htm, css, jpg, jpeg, gif, etc,.. files from a
client machine to two web servers (they are load balanced) within our
company intranet.
2. Use AD for authentication purposes.

1. Provide a browser based solution (these people want WEB, WEB, WEB).
2. Scan the "Dept" folder on one of the hosting web servers. Extract
the names of all department folders within the "Dept" folder to aid in
authentication purposes. This is accomplished by appending the string
"_Pubs" to the end of each department name (thus creating the AD OU)
and using "myPrincipal.IsInRole("domainname<i>\" + Dept + "_Pubs")
3. For users that log into the domain, authenticate against their AD
OU (<i>deptname_Pubs).
4. For users that do not log into the domain, prompt for credentials
then authenticate against their AD OU (deptname_Pubs).

My Solution:
Use a Windows Form Control within an html page. Utilize the System.IO
class for all file scan and copy functions. Utilize the
System.Security.Principal class for active directory authentication.
Note: This solution works perfectly for me because I am an
administrator on the web servers. My users will not be.

Below is the relevant code for anyone interested. Some of the names
and code have been changed to protect the innocent:

The Code
'************************************************* ************************
Public Class ctlWCL
Inherits System.Windows.Forms.UserControl
Dim sServerPath As String = "\\DefaultServer\Shared\"
Dim saFiles(), sSourceFolder, sDestFolder, sSurveyURL As String
Dim objActivePub As Publisher

Private Sub lnkSurvey_LinkClicked(ByVal ...) Handles
'This function provides the url to the user
Dim process As New System.Diagnostics.Process
process.StartInfo.FileName = "iexplore"
process.StartInfo.Arguments = lnkSurvey.Text
End Sub

Private Sub cmdPublish_Click(ByVal ...) Handles cmdPublish.Click
Dim sFullFileName, sFileName, sSurveyName, sTXTName,
sDestDirectoryOne, sDestDirectoryTwo As String
Dim i, j As Integer
Me.Cursor = Cursors.WaitCursor
'Get full File Name
sTXTName = cmbSurveys.Items(cmbSurveys.SelectedIndex).ToStrin g

'Determine the Survey Name
sSurveyName = sTXTName.ToUpper.Substring(0, Len(sTXTName) -

'Build the Destination Directories
If optDevProduction.Checked Then
sDestDirectoryOne = "\\Server5\Docs\" + objActivePub.Dept + "\"
sDestDirectoryTwo = "\\Server6\Docs\" + objActivePub.Dept + "\"
sSurveyURL = "http://PrdURL/Dept/"
ElseIf optStaging.Checked Then
sDestDirectoryOne = "\\Server3\Docs\" + objActivePub.Dept + "\"
sDestDirectoryTwo = "\\Server4\Docs\" + objActivePub.Dept + "\"
sSurveyURL = "http://StgURL/Dept/"
sDestDirectoryOne = "\\Server1\Docs\" + objActivePub.Dept + "\"
sDestDirectoryTwo = "\\Server2\Docs\" + objActivePub.Dept + "\"
sSurveyURL = "http://DevURL/Dept/"
End If

'Copy all survey htm, html, css, jpg, gif, pdc files
For i = 0 To saFiles.GetUpperBound(0)

sFullFileName = saFiles(i).ToUpper
'Allow all files with surveyname and extentions of (HTM or HTML or
'Or all files with .CSS, .JPG, .GIF etc...
If (sFullFileName.IndexOf(sSurveyName) > -1 And
(sFullFileName.IndexOf(".HTM") > -1 Or sFullFileName.IndexOf(".TXT") >
-1 Or sFullFileName.IndexOf(".HTML") > -1)) _"
Or sFullFileName.IndexOf(".GIF") > -1 Or _
sFullFileName.IndexOf(".JPG") > -1 Or _
sFullFileName.IndexOf(".JPEG") > -1 Or _
sFullFileName.IndexOf(".JFF") > -1 Or _
sFullFileName.IndexOf(".JTF") > -1 Or _
sFullFileName.IndexOf(".PNG") > -1 Or _
sFullFileName.IndexOf(".BMP") > -1 Or _
sFullFileName.IndexOf(".TIF") > -1 Or _
sFullFileName.IndexOf(".TIFF") > -1 Or _
sFullFileName.IndexOf(".WMF") > -1 Or _
sFullFileName.IndexOf(".RAS") > -1 Or _
sFullFileName.IndexOf(".EPS") > -1 Or _
sFullFileName.IndexOf(".PCX") > -1 Or _
sFullFileName.IndexOf(".PCD") > -1 Or _
sFullFileName.IndexOf(".TGA") > -1 Or _
sFullFileName.IndexOf(".CSS") > -1 Or _
sFullFileName.IndexOf(".JS") > -1 Then
sFileName = System.IO.Path.GetFileName(sFullFileName)
System.IO.File.Copy(saFiles(i), sDestDirectoryOne + sFileName, True)
System.IO.File.Copy(saFiles(i), sDestDirectoryTwo + sFileName, True)
End If
lblWorking.Text = "Publishing Complete, Please Bookmark The Survey URL
lnkSurvey.Visible = True
lnkSurvey.Text = sSurveyURL + objActivePub.Dept + "/" + sSurveyName +
Me.Cursor = Cursors.Default
Catch ex As Exception
End Try
End Sub

Private Sub cmdBrowse_Click(ByVal ...) Handles cmdBrowse.Click
'This function will allow the user to select the copy from directory
Dim i As Integer
Dim sFileName As String
Dim di As New System.Windows.Forms.FolderBrowserDialog
sSourceFolder = di.SelectedPath.ToString()
If sSourceFolder.Length > 0 Then
lblPath.Text = sSourceFolder
saFiles = System.IO.Directory.GetFiles(sSourceFolder)
For i = 0 To saFiles.GetUpperBound(0)
If saFiles(i).ToUpper.IndexOf(".PDC") > 0 Then
sFileName = System.IO.Path.GetFileName(saFiles(i))
End If
End If
Catch ex As Exception
End Try
End Sub

Private Function AuthorizedPublisher() As Boolean
'This Function Authenticates the User
Dim myPrincipal As New
System.Security.Principal.WindowsPrincipal(System. Security.Principal.WindowsIdentity.GetCurrent)
Dim i As Integer = 1
Dim Dept As String

Dim Departments() As String =
For i = 0 To Departments.GetUpperBound(0)
Dept = Departments(i).Remove(0, Len(sServerPath))
If myPrincipal.IsInRole("domainname\" + Dept + "_Pubs") Then
objActivePub = New Publisher(Dept)
objActivePub.User = myPrincipal.Identity.Name.ToString
Return True
End If
lblError.Text = "Unable To Authorize User!!!"
Return False
Catch ex As Exception
End Try
End Function
End Class
Jul 21 '05 #1
0 2366

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Tim Mulholland | last post: by
7 posts views Thread by jsale | last post: by
reply views Thread by Tess | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.