Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to save a file to server?

Status
Not open for further replies.

icy111

Programmer
Dec 13, 2001
39
US
Hi,

My codes are working fine in local pc. When deploying in IIS Server. It can't detect the source file path.

Have tried using copy & move command in ASP.net 2.0 using VB.
From a list box, there are 3 files that need to be uploaded to the IIS server.

Is there a way to do it?

For i = 0 To lstFiles.Items.Count - 1


iEndPos = InStr(1, lstFiles.Items(i).Text.Trim(), " (File Size")
iLen = iEndPos - 1
strFN = Mid(lstFiles.Items(i).Text, 1, iLen)
sourcepath = strFN

destpath = strPath + strAttachPrefix + CStr(i) + FunctionReference.getfilename(lstFiles.Items(i).Text)




If File.Exists(sourcepath) = True Then
Dim fs As FileStream = File.Create(sourcepath)
fs.Close()
File.Copy(sourcepath, destpath)
End If


If File.Exists(sourcepath) = False Then
Dim fs As FileStream = File.Create(sourcepath)
fs.Close()
End If

File.Move(path, path2)


Next


Thanks in advance.

cheers
icy111

 
From a list box, there are 3 files that need to be uploaded to the IIS server.
Where are these files? On your pc? If so, you'll have to use a FileUpload control to post them to the server. Then,, you can use the SaveAs method to save the files. For more information, see:




____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Hi,

i have try that method upload.postedfile.saveas
The files are from local PC.

We only allow user to upload files from the listbox.

Thanks.
 
this works on your local box because the client and server are the same computer. this won't work on your live server because the server and client are not the same.

If your within an intranet you would need the full path to access the file. [tt]\\computername\drive\directory...\filename[/tt]. if it's not in the same place everytime the user must tell the server where to get the file. this requires a file upload control.

the server will need access the the clients machine. depending on the number of clients this can be many machines.

your best options is to use the file upload control and then validate the file before saving to the server.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi,

is within the intranet.
But how to retrieve the computer name? as there are different user uploading files.

I need to use the listbox because to check total file size uploading can't be exceed 1MB. Only when user confirm, then i need to rename the 3 files to certain file name.

Thanks.

regards
icy111
 
Code:
Dim host As System.Net.IPHostEntry
host = System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST"))
strComputerName = host.HostName

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
hI Jason

This method based on the MSDN help:

"NOTE: This method is now obsolete. "

regards
icy111
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top