The code below always saves file in local machine, why?
When it is run in local machine, it uploads to local machine. When I remote in to the server and run it locally on the server, it upload files on server's local drive.
More likely a misunderstanding about what happens.. A web server can't save on a remote browser side drive without any user action. Could it be an older file from an earlier attempt? Use another file name or delete earlier attempts before trying again.
Is suspect the catch block is triggered but as showing sb is in the else part, nothing is shown and seeing and old file give the impression it was saved.
Not directly related but showing exception messages to uses is likely not that a good idea. The usual approach is to show a generic message and log exception details at a place where those in charge of keeping the site up and running can easily monitor,
diagnose and possibly fix that...
This is triggered from a page on the same server? If yes you could write your app so that it works regardless of where it is installed without any code change (even for example if your app is installed a root web site ie site.com/myapp/MyModal.aspx
Member
12 Points
89 Posts
FileUpload Control Saving Files in Local Machine
Jul 10, 2020 06:06 AM|njehan01|LINK
The code below always saves file in local machine, why?
When it is run in local machine, it uploads to local machine. When I remote in to the server and run it locally on the server, it upload files on server's local drive.
But, when I run it from my local server using this link "http://MyWebServer/MyWebSite/mainpage.aspx", it still uploads and saves files on my local machine.
How do I get it to upload files on the server?
All-Star
194511 Points
28081 Posts
Moderator
Re: FileUpload Control Saving Files in Local Machine
Jul 10, 2020 06:33 AM|Mikesdotnetting|LINK
Server.MapPath resolves a file path on the machine on which the code is executing. The URL that you use to reach the application is irrelevant.
All-Star
48570 Points
18081 Posts
Re: FileUpload Control Saving Files in Local Machine
Jul 10, 2020 06:48 AM|PatriceSc|LINK
Hi,
More likely a misunderstanding about what happens.. A web server can't save on a remote browser side drive without any user action. Could it be an older file from an earlier attempt? Use another file name or delete earlier attempts before trying again.
Is suspect the catch block is triggered but as showing sb is in the else part, nothing is shown and seeing and old file give the impression it was saved.
Not directly related but showing exception messages to uses is likely not that a good idea. The usual approach is to show a generic message and log exception details at a place where those in charge of keeping the site up and running can easily monitor, diagnose and possibly fix that...
Member
12 Points
89 Posts
Re: FileUpload Control Saving Files in Local Machine
Jul 10, 2020 06:52 AM|njehan01|LINK
I've figured it out...
I was using the localhost instead of using the actual server path
Modified opendialog("http://localhost:12345/MyModal.aspx");
As
opendialog("http://MyWebServer/MyWebApp/MyModal.aspx");
All-Star
48570 Points
18081 Posts
Re: FileUpload Control Saving Files in Local Machine
Jul 10, 2020 06:58 AM|PatriceSc|LINK
This is triggered from a page on the same server? If yes you could write your app so that it works regardless of where it is installed without any code change (even for example if your app is installed a root web site ie site.com/myapp/MyModal.aspx