How to check if a HttpWebResponse returns a file or a page - httpwebresponse

How to distinguish if a response is a HTML or a file?
For example, if I request an HTML file from a server(which is built based on SharePoint), the response.ContentType is 'text/html'.
So how to check if the server returns a file or a page? Should I check ContentType property?
Thanks in advance!

All sharepoint pages will have a charset defined with the contenttype. Additionally, no SharePoint pages have a filetype of .htm/.html. For binary file types (other than media and txt) will typically come back as application/octet-stream.

Related

IE9 JSON Data To Iframe: "Do You Want To Open or Save This File?"

I have the same issue as is explained here, in short:
I am using an iframe to post files to the server AJAX-style, then receiving a JSON response to tell me if the file was uploaded and parsed successfully. This works great is every browser except IE9. Instead, IE9 prompts me to save or open the JSON, and will not pass it back to the iframe.
In the other SO question for this, EricLaw -MSFT suggested to set the content type to "application/json", which I have done, but to no avail.
Does anyone know how to get IE9 to let the iframe have its JSON?
Well it looks like setting content type to "text/html" does the trick. It's less than ideal since it's not descriptive of the content, but oh well. Hope this helps someone else too.
HTML Forms are limited to sending data in three different content types: text/plain, application/x-www-form-urlencoded, and multipart/form-data
To workaround this issue, server code that currently processes HTML Forms must be rewritten to manually parse the request body into name-value pairs when receiving requests from XDomainRequest objects. This makes adding support for the XDomainRequest object more difficult than it would be otherwise.
References
XDomainRequest - Restrictions, Limitations and Workarounds
HTML Living Standard: Association of controls and forms - The enctype and formenctype content attributes

Windows Phone 7 Web Browser Navigating to an html file located in a folder within the solution

Uri currURI = new Uri(currentPageToLoad, UriKind.Relative);
ExtrasHTMLbrowser.Navigate(currURI);
The above code basically is grabbing a string (currentPageToLoad) and making a URI. Then my web browser, ExtrasHTMLbrowser, is trying to navigate to the URI. When currentPageToLoad is something like "author.html" it works perfectly, and navigates to the html page.
However, the problem I am having is that when the html file is in a folder such as HTML, it won't navigate properly. So, when currentPageToLoad = "HTML/author.html" the phone will give me the generic 404 not found page.
Any Idea why it would matter if the file was in a folder, or am I trying to access the file incorrectly?
Any help is greatly appreciated, thanks!
-Mark
Set the HTML file to build type Content.Then do this:
var rs = Application.GetResourceStream(new Uri("HTML/author.html", UriKind.Relative));
StreamReader sr = new StreamReader(rs.Stream);
This will read the entire HTML file as a string. You can then use the WebBrowser control's NavigateToString method like this:
ExtrasHTMLbrowser.NavigateToString(sr.ReadToEnd());
If you have images/CSS you want to use, then you'll have to use the above method to read the HTML file as a string and save it into Isolated Storage, alongside the images and CSS files (with matching directories).
In order to be able to navigate between multiple pages you'll first need to copy the files to IsolatedStorage. It's not possible to navigate between pages if you navigate to a file directly within the XAP. (The relative paths are unusable and you can't access such files via an absolute Uri.)

Script to get the HTML files of a URL list, save them and convert them to an image

I am looking for an application or a script, either for Linux or Mac OS X, to retrieve the HTML files of a set of URLs (only the root HTML file), save them to a file and convert the HTML to an image. Anyone? Thanks in advance.
Use
http://ipinfo.info/netrenderer/index.php
to render an snapshot image of any page.
You need to post the form and wait for returned html.
find http://renderer.geotek.de/image.php? in the HTML code.
you'll find imgid and browser just next to it extract the full url
and again using this URL. you'll get the image!!!!!!!!!!!!
Save it...

Headers set on embedding

Lets say I have a URL (http://www.example.com/something). Is the following scenario somehow possible?
A) The user visits the URL directly and a standard page with markup, js, etc. is shown.
B) The user embeds the same URL in an image tag and the URL is served only as an image.
This can be accomplished in any CGI program by checking the HTTP_REFERRER header.
A) In the case of the URL being entered directly the referrer header should be empty. Or if the user came from a link on another site then it will have the URL of that site.
B) When the resource is loaded from an <img...> HTML tag then the referrer header should contain the URL of the page that contains the image.
So by checking the contents of that header your response handler can take different actions.

import from file in javascript

I have a html/javascript table/grid that I need to import data from a file, this is not possible without serverside. So I decides to have a FileEcho server that takes a file upload from the table/grid, the problem is I don't want to refresh the page afterwards, it's a multipart request, not an ajax request. Is it possible to up the file ajax style?
how can this be done? any solution to my problem?
A popular way is to do the file upload in an iframe (you can set the <form>'s target attribute to the name attribute of your iframe)
You can attach an onload event on the iframe to find out when the data has been echoed from the server. From there, you can grab the contentDocument attribute from the iframe object in javascript (from there you could look at the innerHTML content of the contentDocument.body to see the data).
Just note that in IE, you have to use document.frames['frame_name'].document instead of iframeObject.contentDocument
See these articles for more info:
http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
http://www.openjs.com/articles/ajax/ajax_file_upload/

Resources