Re: How to save a uploaded file across server?

G

GrantMagic

Place a the following tag in your html
<input id="myFile" type="file" runat="server">

Then in your code.
First get the file name:
'Logic to find the FileName (excluding the path)
Dim intFileNameLength as Integer
Dim strFileNamePath as String
Dim strFileNameOnly as String
strFileNamePath = MyFile.PostedFile.FileName
intFileNameLength = Instr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath,
(Len(strFileNamePath)-intFileNameLength)+2)

Then save the file:
myFile.PostedFile.SaveAs("C:\SomeDirectory\"& strFileNameOnly)



myFile.PostedFile.SaveAs(Server.MapPath("MINUTEFILES\") & strFileNameOnly)
 
G

Guest

Hi

Thank for the code. I try Server.MapPath but it seem to return my path
where my page is residing in. I think the following example will better
explain what I really need.
In IIS, I have
Application1
--> Folder1
--> Folder11
--> My webpage
--> Folder 2 (physical path pointing to a different drive or different
server)

Is there anyway, when running my webpage I can upload a file that save into
Folder 2 which is actually pointing to either different drive or different
server.

Thanks again

Regards,
Jenny
 
G

GrantMagic

YOu can try creating a network drive(like "z:") or sharing the folder and
referring to its path (\\PCNAme\sharename).

Then when specifying the path do so like that
myFile.PostedFile.SaveAs("\\PCName\ShareName\"& strFileNameOnly)
or
myFile.PostedFile.SaveAs("t:\"& strFileNameOnly)

Before doing this make sure the user (IIS Admin USer) has permissions to
write to the shared folder or network drive. This can get tricky and may
involve impersonating a user to do so
 

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,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top