Recently I was approached to develop an application (asp.net/c#) to allow users to listen some audio files stored in some shared folders.
The users didn't have access to the shared folders, and the files should be streamed. Also, the page should provide the play/stop/pause/forward/back functions, as well as time elapsed/total time information.
So I setup a webservice that access the required file, and return a Byte[] containing the mp3/wav audio (actually I have to convert them to the desired mp3/wav format prior to returning the Byte[]).
The problem is that I have no idea on how to present it in the webpage.
What i need is a webpage with some control that provides the necessary functionalities and information, loaded from a Byte[].
I've researched the web and tried a lot of snippets and controls with no luck at all.
Any ideas or directions on how to implement it?
Thanks in Advance,
António
You could use HTML5's audio tag, if you expect your users to be using fairly recent browser versions. You'd set the src to a URL that would be set up to write your byte[] to the response stream (e.g. maybe store the byte[] in Session, make an .ashx handler page to return that, and set src="myHandler.ashx").
A good approach would be to use silverlight or flash player, even a java applet.
Related
User need to upload 30,000 csv values, these values may contain 16 digit numbers or zipcodes.
Now our asp.net project doesn't use AJAX tool kit controls or jquery or any other 3rd party controls or open source code. This is restriction as per companies privacy policy.
So I have to come with a best way to accommodate file upload feature. This has to be versatile in regards to re-usability some thing like a custom control
This file upload feature should not be saved on the server, instead I need to read data into stream buffer and send them to UI then once user verify these values he/she'll have to hit submit thus values will be saved to DB.
what are the best ways to implement this,
Can I make use of System.Net.Webclient? or
Is there any other alternative ways by using Async HttpHandlers?
Can I show file upload progress to UI ?
Appreciate if you could help me with proper guidence on this.
Thanks in advance
krish
Well 30,000 values of zipcode or any other 16 digit code should be uploadable normally using file control(i mean via postback).
if you have to read and show 30,000 on the UI, i presume you are at risk of freezing your UI.
Moreover if you are not on HTML5, there is no way that you can read the content on the client side, except if you fiddle around with flash.
HTML 5 file api reference
http://www.html5rocks.com/en/tutorials/file/filesystem/
How to read and write files with Flash(Action script)
http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/
I am using ASP.NET 4.0 + IIS 7 to serve up a number of large PDFs via Response.TransmitFile.
The PDFs are all linearized, i.e. "Fast Web View". However the browser still requires the entire PDF to be downloaded before displaying any of it. All I want to do is show the first page (at least) without having to wait several minutes for the entire PDF to download.
From what I have read, the response header should include ["Accept-Ranges", "bytes"] but this does not seem to help.
Can anyone give me some pointers?
Thanks in advance!
I don't think you can do that easily. For byte range to work you would need many requests to serve the same file. How would you associate all these requests with a single file instance? You would probaly need to save the file to disk or somehonw maintain the file in memory... it could get tricky...
Much simpler would be to save PDFs in a shared folder (a first in first out cache) and let the HTTP 1.1 do the rest.
I'm not used to work with remote resources, so maybe this question is trivial, but I'm not sure how to implement it.
I need to load a collection of images that are placed in a http folder, for example http://www.myexsamplesite.com/images.
Inside this directory I could have N images with different names.
I need to show these images in a WinForms application (in a ListView).
The alternative that I'm studying is downloading the images to a tmp dir, and then load them from disk from my WinForms application. I'm using the following:
WebClient fileReader = new WebClient();
fileReader.DownloadFile(imageAddress, filePath);
to download the files to disk. My question is:
How can I download all the files in the http folder? I guess that I need to enumerate the files in the folder and then download one to one.
The second question and most important. I'm sure that there is a much better mechanism to perform this task. So:
Is there any other way to get the http image content into a System.Drawing.Image?
Remember that I need to get all the files in the http folder.
Thanks in advance
First, to get all of the files, you need a way to enumerate them. HTTP does not have any method that lets you download a whole directory, or technically even list what's in a directory. Some web servers are set to send you a pre-defined web page which displays the list of files in a directory when it lacks a default page, but not all are. You could parse that content to get a list of the files you need to download. Otherwise, you'll need to find a way to get that info programmatically, based on the web application itself.
Second, you can load an image from a stream, as I recall. Instead of using WebClient, you can use HttpWebRequest so that you can access the content stream, and feed that into your constructor. However, I think it may be better/easier for you to use a temp directory and load the files from there. Sometimes unexpected things might happen when loading things from a network stream like this (for example, the stream of GIF images with animations is attempted to be kept open to continually read the frames of the animation), which could cause exceptions at odd times you might not be prepared to debug and understand off the bat.
Finally, note that you would only be using mime type here to verify that your content is an image - so you explicitly would not load something that is mime type application/octet-stream into an image object - but only things like image/jpeg, image/gif, image/png etc.
On the server that my application is being run on, a virtual PDF printer is being installed (don't know much about this yet, except it's from Adobe), and my application needs to use this 'printer' to create PDF's from HTML pages (a GridView mostly), and then redirect the user to the URL of the where the PDF is stored.
I've been looking at the PrintDocument object in System.Drawing.Printing, however I've read that you can't simply feed this a HTML page. What are my choices? The easiest option would be to be able to 'print' a given HTML page (choosing what and what not to print using CSS), but from what I've read this is fairly difficult, so I'm thinking about somehow constructing whatever object PrintDocument needs programatically, if that makes sense.
Any ideas on how I should do this?
there are some free/cheap libs for creating pdfs on the fly. I've used itextsharp before and it worked pretty well. Takes a bit of time to get up to speed in how it works but I'd suggest checking it out.
There are also printing services like Neevia DocConverter that will monitor a folder and auto convert whatever you put in the folder to a pdf, jpg, etc. you can set it up so that if you drop a url shortcut in the folder it will render the webpage at that url to pdf. it's a bit more of a pain if you want to do realtime rendering but works excellent for generating mass reports in batches that you want to post up to a website or email later.
I am just playing around and trying to make a very simple CMS. Right now I what I do right now is I use "FtpWebRequest" to get the file that they want to change around and stick it into a jquery plugin call html area(rich html editor).
Now I am wondering how could I allow them to add images that are not already hosted? Ie not on imageshack or something.
I am guessing I need to somehow upload the file and then store it somewhere but not sure how to do all that.
Thanks
A common approach for CMS systems that need to work in low-trust environments (like shared hosting) is to use the FileUpload control, and save the uploaded file as a binary (BLOB) in a database. This avoids dealing with the headache of disk access rights on the web server.
If you're using SQL Server, here's a great article on the database side of things (storing images as BLOBs).
The .NET side of things is pretty straightforward. The FileUpload.PostedFile property has all the information about the uploaded file, including a byte stream of its data.