Results 1 to 2 of 2

Thread: response.binarywrite

  1. #1
    Join Date
    Dec 1969

    Default response.binarywrite

    Hi i am trying to convert the C# equivalent of this:<BR>Response.Buffer = TRUE<BR>Response.ContentType = "image/gif"<BR>[SOME CODE]<BR>Response.BinaryWrite(Chartspace1.GetPicture ("gif", 700, 450))<BR>Response.End<BR><BR>what ive done is this:<BR>Response.Buffer = true;<BR>Response.ContentType = "image/gif";<BR>[SOME CODE]<BR>Response.BinaryWrite(objCSpace.GetPicture("gif ", 700, 450));<BR>Response.End();<BR><BR>However I am getting this error:<BR>- The best overloaded method match for &#039;System.Web.HttpResponse.BinaryWrite(byte[])&#039; has some invalid arguments<BR>- Argument &#039;1&#039;: cannot convert from &#039;object&#039; to &#039;byte[]&#039;<BR><BR>im not sure whats going on because when i do this in c#:<BR>Response.Write(objCSpace.GetPicture ("gif", 700, 450).GetType());<BR><BR>i get this returned: System.Byte[]<BR><BR>Am i missing some syntax somewhere? <BR><BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: response.binarywrite

    Code Below. You may have to change the contentType, but it should still work as long as you name the attachment properly. Netscape has trouble with header attachment names so you may run into a situation where your downloaded file in NutScrape is the name of the page (ie index.aspx) but the content is still valid.<BR><BR>[Use System and System.IO]<BR>using System;<BR>using System.IO;<BR><BR> string fileLocation = [Location]<BR> string fileName = [FileName]<BR> <BR> //Set the appropriate ContentType.<BR> Response.ContentType = "application/octet-stream";<BR> Response.AddHeader( "content-disposition","attachment; filename=" + fileName); <BR><BR> // Open file for Binary Read<BR> FileStream sourceFile = new FileStream(@fileLocation, FileMode.Open); <BR> long FileSize; <BR> FileSize = sourceFile.Length; <BR> byte[] getContent = new byte[(int)FileSize]; <BR> sourceFile.Read(getContent, 0, (int)sourceFile.Length); <BR> sourceFile.Close(); <BR><BR> //Write the file directly to the HTTP content output stream.<BR> Response.BinaryWrite(getContent);

Posting Permissions

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