asp: get file name for a upload file - asp-classic

I am working on a bug fixing for a old asp web page. In this page, there is one field as file for user to browse a file for update. Here is what is like in the asp page:
<input type="file" name="ufile" size="50">
In the browser, this field looks like a text field and a "Browse" button. When use click on another submit button, the input field "ufile" is used for gettting file name for uploading. The asp file has a customized clsMyQuest.asp page to get query string or object. However it looks like broken when the asp project is moved from Windows server to a Linux server.
I don't want to spend time to fix the problem of clsMyQuest.asp file. Is there any way to get the file name in asp for this field "ufile". I guess that the value of this field should be an object of file or something. This object should be retrievable from Request and then the file name may be property of the object. For example, if the user click on "Browse" button to get a file like "C:\Documents and Settings\Documents\user1\example file.pdf", how can I get the file name "example file.pdf"?

If you're using the ASPUpload server component then you can access it by File.FileName
I assume you are running ASP on Mono, since it's a Linux server. You'll need to install the ASPUpload server component. From what i've heard it's tricky to get the component working on Linux
http://www.aspupload.com/

Related

Right click file, call ASP to run command with it

On a Windows desktop I want to right click on a file, choose a custom menu item in the popup list, which when clicked on makes an HTTP request to call an ASP page on a Windows servers. This is all inside a corporate network.
I'm thinking I will right a VB Script to perform the http request so that I can grab the fully qualified file name and pass it as a parameter.
A long time ago I did CGI based web programming using html forms with a submit button to specify the href and the form fields were sent across with the http request as name value pairs.
How can I do a similar thing in the VB Script except call an ASP page (or method) to pass the file name to the ASP page?
In the ASP page what method would the request go to? In that method I will use the file name to do some processing.
A registry entry similar to the following will allow you to right-click on any file and click on a "Do Something" item, which will use PowerShell to submit the URL with the filename at the end as the "file" parameter.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Do Something\command]
#="powershell invoke-webrequest 'http://www.mywebsite.com/?file=%1'"
If you only want this item to be available on certain types of files, then you'll need to do a little research or tinkering to find exactly where to put it. For example, for this to work only .txt files, you would replace the "*" with "txtfile".
If you want only the filename and not the entire path, you can use .NET methods to get just the filename when you process it in the codebehind.
In ASP, use the Request.QueryString to access the filename that was passed in the URL:
Dim ClientFile as String = Request.QueryString("file")

How to get selected file path in the Fileupload control asp.net

I am using Fileupload control to upload file. I am displaying the selected file icon(with achor tag) with file name. if click the icon i want to open the selected file in a new window.
How to take the selected file path from the fileupload control.
Nathiya,
Do you want to open the file BEFORE it is uploaded to the server?
If the file was already uploaded to the server, then you know the file's path since you passed it to the FileUpload1.SaveAs() method.
If you want it before (e.g. someone clicked on the browse button and choose a file but did not upload it to the server) - Then this is not possible as the file is still on the user's local computer (you can't show files that are on the user's computer, only files that are on your server).
What i came to know from the search is it is not possible
As it leads to privacy breach and security breach
Please check this Get Full File path
FileUpload1.FileName will give you the name of a file on a client.
EDIT : As per the comment. You should first upload the file to your server. Then use the path (the url to the file) to set as the href value of an achor tag.

File browser control to replace <input type="file">

I'm working on an ASP.NET web application for our corporate intranet users. I have a form where a user should provide a path to the file on the local network (something like "\localServer\someFolder\someFile.ext") without uploading the actual file. The issue is that users don't want to type the whole file path and want to use some kind of visual browse dialog.
The standard HTML <input type=file> element allows to browse for a file, but most of the browsers (except for IE) don't allow to access file's full path, so I think it should be done by some external component like Silverlight, Flash, Java applet etc.
I tried to do it with Silverlight, but I'm getting a SecurityException when trying to access file's full path using Silverlight's OpenFileDialog class.
This java applet http://jumploader.com/demo_images.html seems to do something similar to what I'm looking for, but it's focused on uploading files - I only need to be able to get file's full path and pass it to the server as a string.
Any suggestions would be appreciated.
Telerik ASP.NET AJAX RadFileExplorer has the functionality you're looking for:
http://www.telerik.com/products/aspnet-ajax/fileexplorer.aspx
You can use their Custom File Content Provider to hook the GUI to your server's file system.
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/server-sideapi/dbfilebrowsercontentprovider/defaultcs.aspx
This should be possible with Flash's uploading capabilities. SWFUpload has an API that you may be able to access from JavaScript to extract the selected file name without actually uploading anything. See docs here, for example getFile():
getFile is used to retrieve a File Object from the queue. The file retrieved by passing in a file id (the id property from a file object) or a file index (the index property from a file object).

Open File Dialog Asp.Net

I am creating an excel report in vb.net using the office interop. When the report is completed I am saving the excel file on the C drive. The users have asked to save file anywhere they want not just the c drive. Can someone give me some code to popup an opend file dialog in asp.net?
I want the dialog to popup in a saveAs in ASP.NET. I know how to do it in win forms, but I am creating an excel report in asp.net and calling the worksheet objects SaveAs property that excepts a fileName. So right now I just hardcode a file name in there. The users want to choose a file location
I think what you want is actually rather simple.
You can't save a file to the user's computer due to security restrictions (would you want a website saving a file to your computer?)
What you need to do is:
Complete report
Save report file to location on server, IE (.../myWebsite/files/GUID/myReport.rpt)
Display link on next screen pointing to the report file
Doing this the user can right-click and save the file to wherever they want on their computer.
You can clean up these files on whatever schedule you would like.
Assuming you are actually talking about a desktop, winforms app then you can use the built in FileSaveDialog.
Official documentation is here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
but there are tons of tutorials explaining it out there:
http://www.google.co.uk/search?q=vb.net+savefiledialog
You can server files with the Open / Save dialog by using Response.TransmitFile().
The user is then presented with a save as dialog where they can choose the filename and the location on their computer.
You normally do this inside a HttpHandler. A simple one is described here:
http://blogs.msdn.com/petel/archive/2005/12/01/499189.aspx

ASP.NET PasswordRecovery Control with Localized content

I am working on a simple portal application using the ASP.NET membership and login controls. I would like to use the PasswordRecovery control to send emails containing forgotten passwords, however my portal requires localization. I have an existing Content Management System that I am pulling the localized strings out of and I would like to link the PasswordRecovery control to that system.
But, it appears that the PasswordRecovery control will ONLY accept a .txt file for the email body...the property is PasswordRecovery1.MailDefinition.BodyFileName
I do not want to use a file on disk, I would like to use the localized content in my CMS.
Is there any way to do this? It occurred to me that I might be able to use the SendingMail event to send my OWN email through the normal System.Net namespace, but that seems sorta cludgy...
Any thoughts?
Thanks,
Max
Try handling the SendingMail event of the PasswordRecovery control. In that event, set the e.Message.Body and e.Message.Subject properties to your localized text.
Found this by googling "BodyFileName localization":
http://forums.asp.net/t/1118242.aspx:
Just bind the property to a key in
your page's localresource file. The
page's local resource file is the file
located in a subdirectory called
app_localresources in your page's
directory. Just use visual studio's
"tools -> create local resource"
option in design view for it be
created for you.
In that file, create a string
key/value pair with something like
Name: myBodyFileName
Value: myDefaultBodyFile.txt
Then bind this to the BodyFileName
property of the login control with
something like
'>
Then just create the sattelite local
resource files for other cultures and
map that key/value pair in those
resources to other body text files.
By the way, if you used visual studio
to create the resource file for you,
then the binding may have been done
for you automatticaly. Just search for
a
"MyChangePasswordControlResource1.BodyFileName"
key in the resource file or something
similar.
Regards, Jorge

Resources