I am using an asp page where I want to have a hyperlink that, if clicked, will load an html page in the browser.\but as i user the asp:hyperlink and I am also giving the path of the html page where the page is stored. However, when clicked, it is not loading that html page..
i am using the hyperlink as:
<asp:HyperLink ID="hlinkTest" runat="server">Preview</asp:HyperLink>
and i am giving the url as
hlinkTest.NavigateUrl = "file:///E:/user/aspnet_app/source/test.html";
what can be the better solution for getting html page in browser..
I would be concerned that by trying to access a specific file location, you're opening yourself up for problems. You might have some real trouble porting the site to a new location.
If the target file is in the same folder as your hyperling source you could use:
hlinkText.NavigateUrl = "~/test.html";
Good luck.
Try:
Preview
Don't forget that the client browser will be unable to load a file: url unless a file with that name and path exists and the user has read access to it. So in the OP's original example, unless the machine running the browser that's trying to load file:///E:/user/aspnet_app/source/test.html has a readable file at E:\user\aspnet_app\source\test.html, they're get a big fat error along the lines of file or directory does not exist or can't be found. Try giving the user an http: URL, absolute (http://www.mysite.org/foo/bar/baz.html) or relative (foo/bar/baz.html). If relative, the path will be taken relative to the URL of the current page.
Related
I got an ASPX file on my Sharepoint. It's supposed to display some simple tables after clicking on it, but instead of it, it's being downloaded to my PC.
There is another file like that in my other folder and it works perfectly fine.
Could anyone give me some advice, how could I fix this problem, please?
Best regards
If the Aspx file is located in Site Pages or Pages library, it should display data directly rather than download if clicking it.
For this issue I suggest you can create a new site page and insert your custom JavaScript logic into the new created page, it should be able to display directly.
I have an html file (which consists of both text and images) in my Documents library (it need not exactly be over there, what I mean to emphasize is - it's not in the internet and not included within the app package since it's dynamic content and created after the app has been deployed).
I want to display the contents of this page within a WebView. How would I go about doing that ?
You can (and should) copy your HTML Files to the LocalState Directory of your App which sits here: C:\Users\YourUSerName\AppData\Local\Packages\YourApp\LocalState.
You then can Access this with: ms-appdata:///local/
Very Basic example:
string url = "ms-appdata:///local/myWebpage.html";
webView.Navigate(new Uri(url));
You can find a lot of Information and samples in this sample download: https://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7
I'm trying to be able to determine which page url the user is loading from the master page.
So far I've been able to use
this.Request.RawUrl
to get the path of the page itself, which works fine for most cases.
However in this particular website, we use a lot of complicated routing, so something like (say)
/Product/5/2/Purchase
might redirect to /Purchase.aspx?ID=5Type=2
of which I'd want the actual aspx file path.
I've also tried this.Request.PhysicalPath, but that doesn't give the route and basically just appends the path the user requested to the virtual directory.
So how can I do it?
An asp.net Page treats a master page as just another control.
So if you want to get the page, you can always use the Page property provided by the MasterPage class.
I used this and worked :
Page.ToString().Replace("ASP.","").Replace("_",".")
When I use simple menu built manually in html and css presents problem with the navigation. When I navigate a page that is inside a folder when i navigate away to somewhere outside of the current folder then the previous folder remains in the url and page not found message appears. I am currently in development stage. not deployed.
sounds like you need to use absolute URLs, not relative ones. so:
http://www.blah.com/category/page.html
or just
/category/page.html
NOT
page.html
It's because you don't return to your root when you try to redirect
e.g.
I have a page called Default.aspx that isn't in a folder and a page Page.aspx in the folder called SubFolder.
Your urls probably look like this to redirect:
Default.aspx
SubFolder/Page.aspx
When you try to redirect from Page.aspx to Default.aspx, you don't return to the root, so the code will look for a page called Default.aspx in the folder SubFolder, but it doesn't exist, that's why you're getting a page not found error.
You should write your urls like this:
~/Default.aspx
~/SubFolder/Page.aspx
I have a web page which displays some report. When I click on the link for excel, it puts all the data that is displayed on the screen into a CSV file and opens a File Download window which lets me either Open, Save or Cancel.
I want to download this file to a specified location programatically without the user seeing the File Download window. I am using a Windows Application. I dont have the code for the website displaying this report hence dont have the dataset. Also, I looked into the HTML that gets generated by doing a view source on the page but I can't really scrape through it to get the data.
Hence I need to know how to download an excel file from a given website to a location on my computer.
Thanks in advance
Rita
Well you'll need to find the appropriate link or post action. You can then use something like:
string url = "http://whatever/.../foo.xsl";
string target = #"c:/excel documents/foo.xsl";
WebClient client = new WebClient();
client.DownloadFile(url, target);
It gets a bit more complicated if you need to authenticate etc though.
I assume that you're showing the web page within a WebBrowser control. You can handle the WebBrowser.Navigating Event and inspect the value of the WebBrowserNavigatingEventArgs URL property to see if string.EndsWith(".csv", CurrentCultureIgnorecase) (or perhaps a more specific test).
If you detect that the link that has been clicked is for a file you wish to download then you can call e.Cancel() = True on the WebBrowserEventArgs instance to stop the browser from proceeding with its normal behavior of opening the File Download dialog. Then you can use .NET's HttpWebRequest and HttpWebResponse classes to manually download the file.
Here's a sample of downloading using these classes
Actually I am doing a screen scraping, so I am not displaying the web page.
What I have done is gone to the URL where the report is displayed on the screen. There is a hyperlink for 'Excel'. I make this hyperlink click from my program itself. On clicking this link, it opens the File Download dialog box.
I have written, the WebBrowser.Navigating and Navigated events, but the control does not come here. Any ideas
1 more thing, the site that I am accessing is java website.