Displaying BLOB data in a Browser - c#

I need to display my BLOB data directly into the IE Browser without saving a temporary file on the hard Disk.
I have successfully implemented the method of retrieving the file from the blob.
Please help me out or direct me to good articles on how to acheive this functionality.
Im using Visual Studio 2005, C#.NET and Oracle

You could do the following in an HTTP handler :
context.Response.ContentType = "multipart/related"; // I think...
context.Response.Write(<blob data here>);
Now this relies on a browser - IE, firefox - that can handle mht files..
If you want to parse the mht file and return html etc.. that would be a whole different scenario!

If you've already code that saves it as a file then all you need to do is to change that to write it to the Response.OutputStream stream instead of the file stream.

Related

how to read the content of PDF file which is opened in the browser

I have a requirement of reading the content of PDF file from browser using c# and then save it locally. There is no physical existence to that file. It is served when file code is provided using the query string. The sample url is like http://something/ReportStatus.aspx?indvl_pk=12334. I am getting no way to do that. Any help is appreciated. Thanks is advance.

Read contents JSON file sitting on webserver from c# code behind

I am trying to read the contents of a JSON file sitting in my github pages repository.
I can navigate and see the file contents in my browser if I specify the url.
If I use the code here:
http://www.codeproject.com/Tips/397574/Use-Csharp-to-get-JSON-Data-from-the-Web-and-Map-i?msg=4615047#xx4615047xx
It claims to "just work", but it doesn't.
All I get back is:
<html><frameset><frame src="URL-TO-JSON-FILE"></frameset></html>
How am I supposed to read the json file and get its contents back as a string. I am using c#?
Once I get the JSON string back I can do the processing I need to do in c#.
EDIT:
According to rawgithub.com those types of urls are not to be used for production. I need this for production. How do production website read remote JSON files that are located on a webserver?
Thank you
Sometimes in github, if you wish to use code from a repository, you must change the url to raw.github.com/ or click on the raw button and use this url.

asp.net check if a file from the Response.OutputStream has been saved/opened

I am building an excel file (using EPPLUS) on a web page which gives the option to either save or open the file.
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=Excel_List.xlsx");
package.SaveAs(Response.OutputStream);
Response.End();
That works fine. I just want to know how can I check if the user has either opened/saved the file?
Is there an event for that?
The simplest answer is you cannot. Once the server has handed the file off to the client ASP.NET has no control over it.
You could, in theory, place a macro in the Excel file to call a URL on your server, but that's assuming the user opens the Excel file and allows for the execution of the macro (which is disabled in modern Excel versions).
You cannot determine it. After the output is generated you have no info about download process or actions that user takes on downloaded file. It is caused mostly by web browser security limitations.
No, that is not what HTTP is for. If you can successfully send all data from the server, you may assume the client has received it all. Client may then discard, save, print, copy, do whatever they like with the data.
If you want to perform such a check, you should do it from the Excel file itself. But then again you shouldn't, because of privacy. If I ever caught an Excel file phoning home, I don't know what'll happen.
It isn't possible to know if they actually opened it in Excel without adding a macro to the file, but there are ways that you can send a confirmation to the server that the download was completed successfully. For this you would need to embed a rich client in the browser to handle the HTTP request rather than doing it with the browser alone. Something like SoftArtisans XFile can be used for this. Our .NET Excel library also comes with an ActiveX control that can manage the download process (called the OfficeWriter Assistant).
Disclaimer: I work for SoftArtisans

asp.net hide download

I am making an application to edit mp3 files. After the editing is finished I want to present a link to download the file. I am just concerned that the file location, if known, can be abused for illegal files. What do I need to do so that, instead of presenting a link to a file on the server, I can store it in memory (which I already have using taglib) and then stream the download without storing it on the server.
You need to use an HTTP Handler to write the file to the user while masking the true location of the file on the server. This will enable you to enforce whatever rules you may have regarding the downloading of the file, such as a one time download.
See: How to create an HTTP Handler
The code inside the handler will need to be unique to your needs, but something along the following lines should help:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "Application/mp3";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=mysong.mp3");
context.Response.TransmitFile(Server.MapPath("~/Files/song.mp3"));
}
You could use a Stream in case you don't want to save an actual file anywhere, but this should get you started.

How to upload files using Yahoo uploader widget in asp.net

Many might have had experience using File Upload widget from Yahoo User Interface library. The docs and community all know how to receive the files on the server using another server technology other than ASP.NET. If anyone has indeed used the widget in their asp.net pages could you share the code on
How to receive the uploaded files Stream/Bytes to a file.
How to check Integrity of the File
How to check if file was received correctly.
Also i would love to do it in single page because doing so i would learn how to differentiate between a normal webpage request and the one caused my file upload widget
Yahoo Upload Widget can be Found here: https://developer.yahoo.com/yui/uploader/.
Have you tried looking at postedfiles collection though? The API looks like it does a standard post. If it does, the just use that collection.
If it doesn't, then you need to use the inputstream property on the request object to read the incoming bytes.
Using something like Fiddler or firebug will tell you how it's making the request. Look for the request type being multipart/mime
edit
Checking the file integrity & whether it was uploaded correctly are pretty much impossible. The only way I can think to do it is to have the user generate a hash of the file then upload the file & the hash & you check the hash is valid. ie not really practical.
All you're getting is a stream of bytes. you have to assume when the stream ends, it ended cleanly & you got all the file.
I answered my own question with code over here.
http://labs.deeptechtons.com/asp-net-tuts/how-to-upload-files-asynchronously-using-yahoo-uploader/

Categories

Resources