HtmlInputFile.PostedFile.SaveAs in IE8 and error "Could not find apart of the path"

B

Big George

With ASP.NET 1.1, now I realized that copying a file to a webserver
folder is not possible with this code:

strFileNameOnly="MyFile.doc"
strImgFilePath=Server.MapPath("../temp/")
HtmlInputFile.PostedFile.SaveAs(strImgFilePath + strFileNameOnly)

It's not possible when IE7/8 has option "Include local directory path
when uploading files to a server" disabled in the Internet Zone. You
get error:
"Could not find a part of the path"

If that option is enabled, then HtmlInputFile.PostedFile.SaveAs works.

How could I save files to a virtual directory folder on webserver
when option "Include local directory path when uploading files to a
server" is disabled?

Thanks!
 
G

Guest

With ASP.NET 1.1, now I realized that copying a file to a webserver
folder is not possible with this code:

strFileNameOnly="MyFile.doc"
strImgFilePath=Server.MapPath("../temp/")
HtmlInputFile.PostedFile.SaveAs(strImgFilePath + strFileNameOnly)

It's not possible when IE7/8 has option "Include local directory path
when uploading files to a server" disabled in the Internet Zone. You
get error:
"Could not find a part of the path"

If that option is enabled, then HtmlInputFile.PostedFile.SaveAs works.

How could I save files to a virtual directory folder on webserver
when option "Include local directory path when uploading files to a
server" is disabled?

Thanks!

Are you sure that this not because of "../temp/" directory? The
difference with "Include local directory path" enabled or disabled is
only in that fact that when this option is disabled (by default) then
IE does not send the complete file path to the server. In your example
I don't see any line where you use file name or path you get from the
client.
 
B

Big George

Are you sure that this not because of "../temp/" directory?
Mmm... what do you mean? /temp/ has aspnet user rights to write on.
Server.MapPath will get the name of the folder of virtual directory on
webserver. Code does work when "Include local directory path" is
enabled.

Here is my function. I get file name or path from client using
HtmlInputFile control.

Public Sub UpLoadImage(ByRef myFile As HtmlInputFile, ByVal
strImgFilePath As String, ByRef Foto As Byte(), ByRef ctrlImage As
WebControls.Image, ByVal pagweb As String)
If myFile.PostedFile.ContentLength <> 0 Then

Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)
strFileNamePath = myFile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse
(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, (Len
(strFileNamePath) - intFileNameLength) + 2)

''''''''' HERE IS THE PROBLEM
myFile.PostedFile.SaveAs(strImgFilePath +
strFileNameOnly)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Foto = Nothing
Foto = PutImage(strImgFilePath + strFileNameOnly)
ctrlImage.ImageUrl = pagweb
File.Delete(strImgFilePath + strFileNameOnly)
End If
End Sub
 
P

Patrice

Have you tried to set a breakpoint or to display strImgFilePath +
strFileNameOnly to see what is the value you are trying to use ?
 
B

Big George

Have you tried to set a breakpoint or to display strImgFilePath +
strFileNameOnly to see what is the value you are trying to use ?

Sure. Error displays value of strImgFilePath:

Could not find a part of the path "E:\webapp\OrgPol\temp\".

WebServer: Windows 2003, IIS6.0
Web app is in ASP.NET 1.1.
Option "Include local directory path" is disabled on IE7 and IE8. (I
just realizaed that it happens with IE7 and IE8)

If I run from my PC (Windows XP, IIS5.0 ) with my IP
http://192.168.5.210/OrgPol/default.aspx
I get same error.

HOWEVER, if I run from localhost
http://localhost/OrgPol/default.aspx
then THERE IS NO ERROR. File is saved correctly on \temp\ folder
(Why??)

It makes me think that it could be something with user rights.
Of course, I assigned on \temp\ folder rights for modifying to ALL
users that I got on my PC. Still same error when running:
http://192.168.5.210/OrgPol/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top