By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

Upload if files from client PC or local network

P: n/a
Hi - I create a input box as follows:
<INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION: absolute;
TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250" size="87"
name="inpJobDescEmpSpec" RunAt="Server">

to allow the user to select a file which I want saved to a SQL Server
database.

On the save I then run this code to insert the document into the database:

'only try and attach file if there is one specified
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of
the authenticating user here.
If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
Dim fs As New System.IO.FileStream _
(inpJobDescEmpSpec.Value,
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
.JobDescEmpSpecDoc = MyData
.UpdateDocument = True
Else
Dim MyData(0) As Byte
.JobDescEmpSpecDoc = MyData
.UpdateDocument = False
End If
impersonationContext.Undo()

(where I am setting MyData to a byte property of my data class)

This works perfectly fine in the development environment (my PC has Visual
Studio and is the web server connectin to a SQL server database on out
network.

I can browse for and attach files with or network paths (C:\Folder\File.doc
or \\Server\Share\Folder\File.doc)

If I connect to the website on my PC from another PC the local drive upload
works fine (C:\Folder\File.doc) but the network upload fails because
somewhere along the way the backslashes are beibng removed so it is trying to
access file \ServerShareFolderFile.doc

Anyone any idea why this is?

Thanks in advance
Siobhan

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 01 Nov 2005 06:57:03 -0800, Siobhan wrote:
Hi - I create a input box as follows:
<INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION: absolute;
TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250" size="87"
name="inpJobDescEmpSpec" RunAt="Server">

to allow the user to select a file which I want saved to a SQL Server
database.

On the save I then run this code to insert the document into the database:

'only try and attach file if there is one specified
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of
the authenticating user here.
If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
Dim fs As New System.IO.FileStream _
(inpJobDescEmpSpec.Value,
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
.JobDescEmpSpecDoc = MyData
.UpdateDocument = True
Else
Dim MyData(0) As Byte
.JobDescEmpSpecDoc = MyData
.UpdateDocument = False
End If
impersonationContext.Undo()

(where I am setting MyData to a byte property of my data class)

This works perfectly fine in the development environment (my PC has Visual
Studio and is the web server connectin to a SQL server database on out
network.

I can browse for and attach files with or network paths (C:\Folder\File.doc
or \\Server\Share\Folder\File.doc)

If I connect to the website on my PC from another PC the local drive upload
works fine (C:\Folder\File.doc) but the network upload fails because
somewhere along the way the backslashes are beibng removed so it is trying to
access file \ServerShareFolderFile.doc

Anyone any idea why this is?

Thanks in advance
Siobhan

The problem is that inside strings, the backslash is considered an escape
to allow special characters. So you may use double slashes.

Nov 19 '05 #2

P: n/a
the problem is credentials forwarding. by default (and with ntlm impossible)
its not allowed to forward user credentials from a second machine to a third
(1 hop rule).

when you are on your local box, iis and asp.net has a primatuy token and can
talk to network resouces on other machines. if you connect to your pc from
another, then iis and asp.net no longer have a primary token can can not use
the token to talk to another resource.

if you switch to kerberos and enable forwarding you will able to do what you
want.

http://support.microsoft.com/default...b;en-us;810572

-- bruce (sqlwork.com)


"Siobhan" <Si*****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Hi - I create a input box as follows:
<INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION:
absolute;
TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250"
size="87"
name="inpJobDescEmpSpec" RunAt="Server">

to allow the user to select a file which I want saved to a SQL Server
database.

On the save I then run this code to insert the document into the database:

'only try and attach file if there is one specified
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As
System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of
the authenticating user here.
If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
Dim fs As New System.IO.FileStream _
(inpJobDescEmpSpec.Value,
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
.JobDescEmpSpecDoc = MyData
.UpdateDocument = True
Else
Dim MyData(0) As Byte
.JobDescEmpSpecDoc = MyData
.UpdateDocument = False
End If
impersonationContext.Undo()

(where I am setting MyData to a byte property of my data class)

This works perfectly fine in the development environment (my PC has Visual
Studio and is the web server connectin to a SQL server database on out
network.

I can browse for and attach files with or network paths
(C:\Folder\File.doc
or \\Server\Share\Folder\File.doc)

If I connect to the website on my PC from another PC the local drive
upload
works fine (C:\Folder\File.doc) but the network upload fails because
somewhere along the way the backslashes are beibng removed so it is trying
to
access file \ServerShareFolderFile.doc

Anyone any idea why this is?

Thanks in advance
Siobhan

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.