OpenFileDialog opens, but behind all other windows (ASP.NET - VB) - asp.net

I'm having an issue with the OpenFileDialog class, where the OpenFileDialog window will open, but only behind every other application I have running in my OS. I've been hesitant to ask about this, but my search using many different keywords on Google, and searching other forums, has turned up nil. I'm using the following code in a button click event of the button on my web form I want the user to click on to open the file dialog:
Dim fd As New OpenFileDialog()
Dim strFileName As String = ""
fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\"
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog = DialogResult.OK Then
strFileName = fd.FileName
End If
The dialog box opens - it just opens behind every other window...what am I missing here? Am I just going to have to do a funky workaround by minimizing everything when I call the OpenFileDialog class? All I need is for the window to show in front of the browser and every other window. Thanks in advance for your help!

openfiledialog has no place in a standard ASP.NET application. If you call ShowDialog on it, the dialog will open on the server computer (under what user session?) unbeknownst to user looking at the browser window on the client.
Use <input type="file" ... or FileUpload server control to let user select a file to be uploaded to the server.

Related

Why doesn't my hyperlink work?

I have an asp.net page with a hyperlink tag, the idea is that I want to be able to click on the hyperlink (which will have the address of a directory on the system) and be able to open up the directory.
My hyperlink tag is within a gridview and the code for it looks like this:
<asp:HyperLink ID="eFileHyper" runat="server" Text='<%#Bind("hyperlink")%>' NavigateUrl='<%#Bind("hyperlink")%>' Target="_blank"></asp:HyperLink>
I have some code in the back end that adds "file:///" to the start of the address, like this:
Dim dr As DataRow
Dim dt As DataTable
dt = CType(Session("newEFileTable"), DataTable)
dr("lastUpdated") = Now
dr("hyperlink") = "file:///" & hyperLink.Text
dt.Rows.Add(dr)
' Update session table
Session("newEFileTable") = dt
' update gridview - This binds the Session to the gridview
BindEFileData()
If I enter in a directory like this \\server\directory\subdirectory it appears as - file:/// \\server\directory\subdirectory and it works fine.
If I enter a directory as C:/directory/subdirectory it appears as file:///c:/directory/subdirectory but clicking on it does nothing.
Why would one of these work but the other doesn't?
Update The \\server\directory\subdirectory and C:/directory/subdirectory are unrelated. The C:/ one is of course local, the other one is an address to a file on the server.
The latest versions of browsers disable links that point to local content (unless the link is in a file) as a security feature.
See Workaround for href="file://///..." in Firefox
Also, search for "iis enable local file links" and you get lots of hits. It looks like you can work around this by disabling relevant IE security: https://superuser.com/questions/149068/how-to-add-a-local-file-to-trusted-zone-in-ie8. I can't test that right now as I'm at work and browser settings are locked down.

WatiN FileUpload press open Button to fast

I have the Problem with the File Upload window. When I used it the first time it works perfect but when I call the same functionality to open and upload a File the open button (in the "Choose File to Upload" Dialog) is pressed to fast. So the Test can not write the complete path of the File over set and so the I can not open the File.
The Source Code of the function:
public void OpenFileDialogAndUploadCsvFileWithName(string fileName, IE editPage)
{
var fileUploadDialog = editPage.HtmlDialog(Find.ByTitle(PageTitle));
fileUploadDialog.WaitForComplete();
FileUpload fileUpload = fileUploadDialog.FileUpload(Find.ById(new Regex("_FileUpload")));
fileUpload.Set(fileName);
Image image = fileUploadDialog.Image(Find.BySrc(new Regex("/icons/upload.png")));
Element parentElement = image.Parent;
parentElement.FireEventNoWait("onmouseup");
parentElement.FireEventNoWait("onmousedown");
}
The Upload File Dialog is open from Internet Explorer Modal Dialog Window.
You might find that the file upload dialog handler is running on a different thread, and that is why you don't get a chance to enter your text.
If that is not he case, and it really is a problem with the dialog handler then I would grab the code for the fileUploadDialog handler and create my own, custom, slower version.

Download/Save/Write a file on the client's hard disk using flash/flex

I wonder how can I download/save/write a file from my server to a client's computer using flash or flex.
An example of what I'm looking for is
avilable on
http://www.flexdownloads.com
Sign up
Sign in
Click on the ("FREE") button placed on the right of the page. (the
orange button)
Choose any product (won't cost you anything)
Press "BUY NOW"
then you'll see a confirmation popup
for the download, then you choose
where do you want to save the file,
and the flash movie saves the file!
Use FileReference
http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7.html
var request:URLRequest = new URLRequest("index.xml");
var fileRef:FileReference = new FileReference();
fileRef.download(request);

pdf will load if use 'save link as' but not if user clicks on the link

After submitting a form, the user is presented with a link to a pdf document.
The link is straight to the document, it is not streamed.
If the user right-clicks and chooses 'save link as,' the document saves and opens fine. However, if the user just clicks on the link, the browser takes a very long time to respond (I'm going to guess it's 3 minutes) and then adobe reader gives the following error:
"the file is damaged and could not be repaired"
This is in Chrome v5, ASP.NET 3.5 and the link is returned inside an UpdatePanel.
it depends on browser settings that are configured for PDF Links. If you change the settings in broweser, you will get the download dialog.
Mozilla Firefox
Open Mozilla Firefox
Click Tools and then Options
Within the Options window click Applications
Select the Content Type you wish to adjust. For example, if you want to change how a .PDF file opens in Firefox, select Adobe Acrobat Document.
In the Action section, change the action to how you wish to open the file. If you want to download .PDF files instead of opening them, select Save file.
Internet Explorer:
You have to right click and click save target as to download.
The other option is, create a seperate asp.net and write below code to download the PDF
private void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
I've had this issue before and the cause was the PDF itself.
Adobe has a slew of causes for this: http://kb2.adobe.com/cps/328/328233.html
FWIW, my PDf issue was solved by opening the PDF in Adobe and going to Document -> Reduce File Size -> Make Compatible with Version 7. (current version - 2)

Programmatically open a new tab in ie7

I am developing web applications with c#, Aspnet 3.5, and Ajax 2.0.
Question - I run Application_1 in ie7. I would like to programmatically start running Application_2 from Application_1 in a new tab, no matter what the client settings are.
Until now I have been opening Application_2 in a new window from Application_1 using
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "window.open('theurl',' width=800, height=500'); ", true);
I would like to do something similar to open a new tab.
Unfortunately there is no way to control whether the window opens in a new tab or new window. This is a user setting that can't be overridden in code.
Here is Microsoft's justification if you're interested.
"Regarding script, there is no "target='_tab'" feature or any direct access to tabs from script beyond what is available with multiple windows today. We are working on balancing the default behavior for whether a window opened from script opens as in a new frame or a tab."
IEBlog
You could inform your user that by holding ctrl+shift and clicking a link will open in a new tab.
As Paul already noted, this cannot be done via any script or code.
I think it's best to let your users decide (via their individual browser settings) how they want to open the new page - in a new window or in a new tab in the same window.

Resources