Can I zip Response.write? - c#

Let me explain better than what the question state. I dynamically generate a KML file from an aspx page and use routing to change the url so I can access myapp.com/mykml.kml and the download starts. I use Response.write() in the aspx page to send the data and it work flawlessly. But there is a zipped version for KML files which is KMZ and I am wondering if I can still use my aspx page to serve a KMZ instead of a KML. Since I do not use a file I cannot "zip" it. Is there a way to zip the stream and output it in the Response.Write()?

Yes, you can: ASP.NET - Create Google Earth .kmz files dynamically using in-memory streams and #ziplib

Related

Load picture from a .NET assembly resource in a simple HTML file?

I have a .NET Server Control app that simply returns some HTML. I also need to embed several picture files into the assembly so that the HTML file can use them as its src= for each of them.
We will simply have a .HTML file that lives in the project as an embedded resource and the server control code will read this html and serve it up. Within THAT html, we will need to have all the picture src links (as well as CSS, js, etc) to point back to embedded resource files.
Does anyone know what code I would put in the HTML file for the pictures to make it point back to the embedded picture file?
I have to do this on a grand scale... hundreds of times. I really would like a programmatic approach to doing this so I can write a wrapper and never have to touch it again when we update the server control with new html, picture files, etc.
One might imagine a way to do this at compile time where I can loop through the embedded files with GetManifestResourceNames and then replace() the src links with the HTTP resource links I suppose?
Thank you for any guidance!
Hm, your question covers quite many aspects. Let me repeat to see if I got it: You have an assembly, with a raw HTML file in it. This file references some items, which are to be found within this same assembly, and you want to have them served to the client upon request as well.
One possible solution might be this.
Instead of a raw HTML file, use a templated one. Then, feed all available resource names as proper URL's into the templating engine, to replace the placeholders.You may want to look at DotLiquid for this.
Create a HTTP handler for each file type you want to serve. Inside the handler, you pull the item from the resources of the dll and serve them.
Alternatively, if those resources are rather small, you want to have a look into the data URI scheme, to save the extra requests and omit the handler. With this you could replace the placeholders with the data URI's directly, and serve a single HTML file with everything in it in the frist place.
Another choice is to have your .NET Server Control app check for optional GET arguments and return the image instead of the HTML.
Your original HTML request might be a simple:
GET netServerApp
Which returns the HTML with normal embedded links.
The HTML image links in the HTML might look like this:
<img src="netServerApp?src=Image1.svg">
or the like. Your server app would then return the appropriate image, instead of the HTML.
It means several round trips to get everything, but that is normal for HTML anyway.

How to cache web to read offline in webcontrol window phone

I'm using to load website follow code
webContent.Navigate(new Uri(linkURL));
I want to cache all content and html tag, style, js in web to read offline.
I tried download html source, file css and js using Webclient and replace these file to html resource then save to file "index.htm" but not good.
Can you find the way to resolve this issue? thank you.
The only way to do this is to download ALL the relevant files (including those referenced inside the HTML. eg. images, css, js, etc.) and save them ALL to Isolated Storage with appropriate similar file and folder structures.
The important point is that you also need to update all the paths within the content so that they point to relative paths that match where files have been saved.
You can then load the HTML from IsolatedStorage.
This is potentially a lot of work. I'd recommend exploring other options if possible first. Also remember to manage the files stored in IsolatedStorage appropriately so you don't just keep adding files there indefinitely.

How to open any file in a iframe

i am using a iframe in my web page. I want to open a file c:\Dir\SubDir\xyz.doc inside a iframe.How to do this ? I checked out many sources ,all of them specified to give the source of the iframe to the path by adding the code.Its not working for me. Here is my code
iframe1.attributes["src"] ="c:\\Dir\SubDir\xyz.doc"
assuming you want to open a file on the client's computer, you would need to use a file URL, such as "file://c|/Dir/SubDir/xyz.doc". that said, it still may not work correctly for various reasons (probably primarily security-related).
if my assumption is wrong and you want to display a file on the server, you still need to use a URL and not a file path, meaning you'd have to have the file somewhere under the document root: "../Dir/SubDir/xyz.doc" for example.
then there is the strong likelihood that a .doc file will not render correctly on a webpage.
<iframe src="test.doc"></iframe>
above example is working in my environment, cause I put file inside my project folder and access that file from there..
you can not open any file out side of your project folder.... So please keep this in mind.
#jcomeau_ictx is right you cannot open .doc file in browser but yes it will ask you to save file, if you put in iframe..

Download all the links from any page

I want to develop an asp.net page through which I can specify the URL of any page which contains links of many files & directories. I want to download them all. Similar to DownThemAll plugin of FireFox.
i.e.
"MyPage.htm" file contains many links to files/directories located on the same server.
now I want to write a function which can download all these file if I provide
"www.mycustomdomain.com\Mypage.htm" as input.
I hope question is clear.
Fetch the web page as HTML. Google (c# fetch file from web). The first link will give you the idea.
Then find the links with regular expressions.
Some example regex pattern for links in www.x.com should be as
(http://www.x.com/.*?)
(But better if you also include the A tag in your regex pattern)
And download the files as shown in:
http://www.csharp-examples.net/download-files/
Hope I understand your question. You have a HTM file with a list of links and these links are links to specific files on a remote server and you want to download all the files.
There is no fail proof way to do this.
Check this question. How do you parse an HTML in vb.net Even though this is for VB.net it is related to what you asked for. You can get an array of links and then start downloading the files.
You can use the Computer.Network.DownloadFile method to download the remot file as save it on a location of yours.
Thi is not a fail prrof method because if a download requires authentication then it will download the HTML page [mostly loin page]

upload image file without post back in asp.net

Does anybody know how can I upload an image file in a specific folder without post back
using c# .
There is no way to do this. But you can accomplish it using AJAX. Take a look at jquery and some it's plugins, for example jQuery File Upload Plugin
You could use flash and an HttpHandler to prevent the requirement for a postback.
I have use this example in the past: http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

Categories

Resources