473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Multiple File copy to Web Server

Hi,
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
questions.

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.

Appendix
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.

Requirements:
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
lnkSurvey.LinkClicked
'This function provides the url to the user
Dim process As New System.Diagnostics.Process
process.StartInfo.FileName = "iexplore"
process.StartInfo.Arguments = lnkSurvey.Text
process.Start()
End Sub

Private Sub cmdPublish_Click(ByVal ...) Handles cmdPublish.Click
Dim sFullFileName, sFileName, sSurveyName, sTXTName,
sDestDirectoryOne, sDestDirectoryTwo As String
Dim i, j As Integer
Try
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) -
Len(".txt"))

'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/"
Else
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
TXT)
'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
Next
lblWorking.Text = "Publishing Complete, Please Bookmark The Survey URL
Below"
lnkSurvey.Visible = True
lnkSurvey.Text = sSurveyURL + objActivePub.Dept + "/" + sSurveyName +
".htm"
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
di.ShowDialog()
Try
sSourceFolder = di.SelectedPath.ToString()
If sSourceFolder.Length > 0 Then
lblPath.Text = sSourceFolder
saFiles = System.IO.Directory.GetFiles(sSourceFolder)
cmbSurveys.Items.Clear()
For i = 0 To saFiles.GetUpperBound(0)
If saFiles(i).ToUpper.IndexOf(".PDC") > 0 Then
sFileName = System.IO.Path.GetFileName(saFiles(i))
cmbSurveys.Items.Add(sFileName)
End If
Next
End If
Catch ex As Exception
..
..
..
End Try
End Sub

Private Function AuthorizedPublisher() As Boolean
'This Function Authenticates the User
Try
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 =
System.IO.Directory.GetDirectories(sServerPath)
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
Next
lblError.Text = "Unable To Authorize User!!!"
Return False
Catch ex As Exception
..
..
..
End Try
End Function
End Class
Jul 21 '05 #1
0 2540

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: caro | last post by:
Hi I am trying to write two Select * statements to the same text file using bcp (from a stored procedure). But cannot find a way of appending to a file using bcp. Does anyone know if this...
10
by: Tim Mulholland | last post by:
My company is about to begin working on an ASP.NET application. There are going to be two primary developers working on this project. It will be a fairly deep project (lots of lines of code) but...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
0
by: Tess | last post by:
Hi, 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,...
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing types...
11
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found...
2
by: ghart | last post by:
Hello all, I have been trying to determine the best way to do this, but can't seem to get any solution to work exactly the way I want. The scenario is that I have some xml files being placed on...
3
by: Tim | last post by:
Hi Folks, I'm used to a UNLOAD command that allows me to dump to a named flat file the results of any SELECT statement. Hence one can build a single SQL file which contains multiple SQL...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.