Sending an Excel document through an ASP page.

Results 1 to 2 of 2

Thread: Sending an Excel document through an ASP page.

  1. #1
    Lee Powers Guest

    Default Sending an Excel document through an ASP page.

    A project that I&#039;m consulting on needs to make certain Execl and Word documents available on the web, but the availability of these documents must be limited to a select few. So, I decided to create a login system in ASP which would output an Excel or Word file if the visitor entered a valid username/password combination.<BR><BR>I&#039;ve hit a bit of a snag in sending these documents from an ASP document to the user. Consider the following code snippets:<BR><BR> First attempt:<BR> <BR> var Connection = Server.CreateObject(&#039;ADODB.Connection&#039;); <BR> Connection.Open(&#039;torr&#039;);<BR> var rst = Server.CreateObject(&#039;ADODB.Recordset&#039;);< BR> rst.Open(&#039;SELECT Data FROM Documents WHERE ID=1&#039;, Connection);<BR> Response.ContentType = &#039;application/x-msexcel&#039;;<BR> Response.BinaryWrite(rst(&#039;Data&#039;));<BR><B R> This fragment fetches a sample XLS file stored in an Access database binary BLOB field, and just writes it to the browser. The browser (IE 5.0 and N4.0) both give the user the "open or save" dialog box. I save the XLS document and procced to open it in Excel, but Excel can&#039;t parse it.<BR><BR> Second attempt:<BR><BR> var Stream = Server.CreateObject(&#039;ADODB.Stream&#039;);<BR> Stream.Type = adTypeBinary;<BR> Stream.Open();<BR> Stream.LoadFromFile(&#039;e:homeprivatesamples.xls &#039;);<BR><BR> Response.ContentType = &#039;application/x-msexcel&#039;;<BR> Response.BinaryWrite(Stream.Read());<BR><BR> Stream.Close();<BR> Stream = null;<BR><BR> This code uses the brand-spanking new ADODB Stream object. But it gave me the same results as the database method.<BR><BR> Third try:<BR><BR> Response.ContentType = &#039;application/x-msexcel&#039;;<BR> Response.Redirect(&#039;samples.xls&#039;);<BR><BR > This is the simplest method, and the only one that actually works. The problem is, Response.Redirect will only go to files in the WWW publish directory, which negates the whole login system. I guess I could password protect a directory in the WWW directory, but I need seperate usernames and passwords for each "chosen" user and not all users can access the same files.<BR><BR>Anybody got any ideas?

  2. #2
    Sachin Guest

    Default RE: Sending an Excel document through an ASP page.

    hey why are you redirecting the user to the file.I have one idea for that<BR><BR>Response.ContentType = "application/csv"<BR>Response.AddHeader "Content-Disposition", "filename="& sid &".csv;"<BR><BR>Where sid is the username<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts