Web Home

SDK Home


Test PHP

Test ASP









Contact Us


JavaSonics ListenUp is no longer for sale.

Writing Server Scripts with ASP.NET

Use Plain Text

The first thing you must do in your ASP script is to set the content type to plain text. This simplifies the text that is sent back to ListenUp, making it easier to parse. These header values must be set before you send any other text! Here is some ASP code that may work for you:

response.ContentType = "text/plain"
response.Charset = "ISO-8859-1"

If you need to set response content prior to setting the ContentType as above, you should buffer your response before sending it. To do this, set the BufferOutput property to true so the entire page will be processed before any content is returned to the client:

     response.BufferOutput = true;

When you're done, call Flush() to send the completed response to the client:


Receiving Uploaded Files

The Files collection in the Request object is a collection of HttpPostedFiles. The .Net Framework includes the class HttpPostedFile in the System.Web namespace. A HttpPostedFile object encapsulates a file that has been included with a multipart/file POST request, such as that issued by the ListenUp client.

System.Web.HttpPostedFile file = Request.Files["userfile"];

Getting Variable Data (Name/Value pairs)

The ASP.NET Request object has a property, .Form, that is a collection of POST name/value pairs accompanying the request. You can use this to discover information sent along with the uploaded file. For example, to get the duration of the uploaded file in seconds:

duration = Convert.ToDouble( Request.Form["duration"] );

Getting Information about the Uploaded File

After you've got your file in an HttpPostedFile object, you can retrieve specific information about the uploaded file by looking at the properties of the object. For example, to view the size and suggested name of a file called "userfile", you can use the following:

upfile_size = file.ContentLength;
raw_name = file.FileName;  // contains fully-qualified path
fileInfo = new FileInfo( raw_name );
upfile_name = fileInfo.Name;  // extract just the name from the path


It is possible that someone could create another program that pretended to be ListenUp and send you some bogus files. So you should check to make sure that no-one is uploading a file that is too big.

if( upfile_size > upfile_size_limit)
  Response.Write( String.Format("ERROR - script says file too large, {0} > {1}\n", upfile_size, upfile_size_limit) );
  err = true;

Save file to destination

Save the file to its final destination. IIS must have permission to write into that folder.

String upload_dir = "../uploads";
file.SaveAs( Server.MapPath(uploads_dir + "\\" + upfile_name)  );


Large Files

HttpPostedFiles are buffered to disk temporarily if they exceed a size that can comfortably be held in memory by the server. By default, ASP.NET limits Request objects to 4Mb total size. If this isn't large enough for the files you're working with, you can override the limit for the server using machine.config, for that particular application using web.config, or even for the page. See the .Net documentation for the HttpPostedFile class for details.


It's quite common to run into a conflict between Windows and IIS permissions. If your application is set up to require authentication, the authentication method will determine the user account that is used to write an uploaded file: it may be the IIS_USER account, or the Windows account of the logged-in user. If the destination directory is not set up with the requisite access control, your call to .SaveAs or .Move may fail.

Debugging this kind of problem can be somewhat painful. Start by setting authentication requirements for your ListenUp app to Anonymous (no authentication required), make sure the uploads directory has Read and Write permission for Everyone, and that IIS has Read and Write access to that directory. See for a decent overview of troubleshooting this kind of problem.

Return Status Codes

Your script must return a status code of SUCCESS, WARNING or ERROR at the beginning of a line. For example:

     Response.Write( String.Format("SUCCESS - {0} uploaded.\n", upfile_name) );


[Top] [Previous][Next]

© 2001-2006 Mobileer, Inc.   This page is from the ListenUp SDK. You can download the SDK from here.