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.
Related
Below is my front end
<asp:Label runat="server" ID="lblContent"></asp:Label>
Backend
Dim db As New Db
lblContent.Text = db.SiteContents.Where(Function(c) c.CTitle = "links").SingleOrDefault.CText
Iv tried everything but I cant add styling and all I want to do is change the font size , any ideas?
Based on CSS language rules you can add your style by key = value like this:
lblContent.Style.Add("font-size", "30px")
Note that: All you have to set needs to be done before rendering (on load event or somewhere). If you are doing that by a button the page needs to be refreshed.
You can try this in the frontend, fetch the element using ID and then update the style of the fetched node.
document.getElementById("lblContent").style.fontSize = "large";
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.
I'm working in ASP.NET (2.0) and we have a page where a user is able to select and download a series of files as a zip. I got this to work without undo difficulty by using the DotNetZip library (which is probably not relevant to the problem, but included for completeness.)
After the user checks which files they want to download, the page does a postback, and in the button click event handler, I use the following code:
Response.Clear();
Response.BufferOutput = false; // false = stream immediately
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=FileRequest.zip");
using (ZipFile zip = new ZipFile())
{
zip.AddFile(MapPath("/datafiles/fileToZip.pdf"), "");
zip.Save(Response.OutputStream);
}
Response.Close();
And this all seems to work great. The user clicks the button, a download window pops up, the user downloads the zip. All is good...
...until they decide they want to do something else on the page. The buttons in the form are no longer responsive. For instance, if I click the download button again, it does nothing. If I reload the page, I can repeat this behavior...it works once, then does nothing.
I'm not understanding why the browser doesn't send the new request. It's not "spinning" or otherwise acting busy. I thought that this might be a browser issue, but I've repeated it in both IE and Firefox, so it seems likely that it's something I'm not understanding. Strangely, it's only form submission elements that seem to be non-responsive. Javascript still works, and so do regular links.
So why is this happening, and how do I get around it?
The problem is likely down to you returning;
Response.ContentType = "application/zip";
Once this has been sent (along with the actual content), the browser would assume it has nothing left to do (I believe).
You probably should create a new window specifically for downloading the files by saving the file selection in a session parameter (or equivalent) and opening a popup window that has your download code in.
This will leave the parent page in a suitable state.
Content-disposition header seems to be a discouraged solution. But the same effect of ASP.NET forms not being responsive occurs if you use standard Redirect to a zip file.
I solved very similar problem (returning *.csv files by the server for download) using Tančev Saša's code in "Response.Redirect to new window" Q&A and it works great. Perhaps it might produce some popup warnings in some browsers, but I think this is how it's often done in download sites.
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.
I am trying to convert my web application into a fully dynamic system. One thing I am trying to do is to load a different logo (set in the masterpage template) depending on the host.
But, even though the code is hit (in page_init), there is no image displayed on any page inheriting the masterpage - no image, no red x's, nothing.
My code looks like this (from masterpage, the path to the image is correct and pasted from Windows Explorer's property window path):
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Request.Url.Host.Contains("localhost") Then
Image1.ImageUrl = "C:\Users\firstname.lastname\Documents\Visual Studio 2008\WebSites\ecardsystem\images\ECard Platform.jpg."
End If
End Sub
I know that I can add the image on the fly using literal controls through codebehind, but this will mean I need to design the html too, by hand, when the design is all done and perfect. Thus this approach will create a bit more work.
Thanks
Have you tried using a virtual path to the image relative to you website? Internet Explorer will generally not show images from a users local file system with the default security settings. Try putting the image in an images directory in your project and setting the URL to it's relative path:
Image1.ImageUrl = "~/images/Card Platform.jpg."
Problem is that
~/images/Card Platform.jpg.
will transform to say c:.SiteFolder\images\card
It finds the image on local server but when this page goes to client..say some xyz person opened same page... the file is not found in his machine..at path..c:.SiteFolder\images\card
The corrected ans is
we should give image path relative to site name:-
like http://localhost:88/images/card
something like this....