Saturday, May 30, 2009

Stream data directly to website user

// Stream data directly to website user

FileStream liveStream = new FileStream(localfilename, FileMode.Open, FileAccess.Read);

byte[] buffer = new byte[(int)liveStream.Length];
liveStream.Read(buffer, 0, (int)liveStream.Length);
liveStream.Close();

Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + originalFilename);
Response.BinaryWrite(buffer);
Response.End();

9 comments:

  1. Hi,
    Kishore U can use the follwing code to prevent Unautoized Downlaod..

    FileStream liveStream = new FileStream(Server.MapPath(".") + "//App_Data//AvinashtiwariStreaming.doc", FileMode.Open, FileAccess.Read);

    byte[] buffer = new byte[(int)liveStream.Length];
    liveStream.Read(buffer, 0, (int)liveStream.Length);
    liveStream.Close();

    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Length", buffer.Length.ToString());
    Response.AddHeader("Content-Disposition", "attachment; filename=" + "AvinashtiwariStreaming.doc");
    Response.BinaryWrite(buffer);
    Response.End();

    ReplyDelete
  2. How to stream download from direct links ?
    I have some limitations to access the files larger than 100 MB in university, I have downloaded some files before so that when downloading u can't get the total size or whatever (I think they call it stream download)(But in direct link downloads the size of the file is known at first) so I was thinking how to stream download direct links ? Thanks

    ReplyDelete
  3. It Totally depends What R the Restricion on UR network..


    If The restruction is Held By ISPor service Provider Then U may Not able to Broke easily and Answer cannot be Given On Open froum ..

    But if U R Restricted By Collge There serval ways..

    1} Flush Your DNS

    2} U may Use proxy such as "Utra Surf"

    3} U may Use Orbit Downloader to Continue From Halfway if Downlaod fails..

    //See My Other Blog How Downlaod File Using
    Mozilla, Got Flash and Orbit Downloder

    http://videosforhack.blogspot.com/2009/10/download-any-movie-from-net.html

    ReplyDelete
  4. HOW WE CREATE LOGIN PAGE WITH CONNECTIVITY WITH ASP APP_DATA DATABASE.MDF
    HOW WE CREATE THAT PAGE PLEASE TELL ME

    ReplyDelete
  5. Hi,

    if You are talking about Asp.net then chk the link

    http://www.4guysfromrolla.com/articles/110905-1.aspx

    if Your talking about MDF connection to classic asp

    http://www.megasolutions.net/Sqlserver/how-to-connect-to-MDF-file-with-classic-ASP_-39493.aspx

    http://www.developmentnow.com/g/100_2007_3_0_0_949076/how-to-connect-to-MDF-file-with-classic-ASP.htm

    chk the above link

    ReplyDelete
  6. Can you let me know, How to detect only the close (x) button click event using javascript for firefox browser?

    I have the below code snippet:
    window.onbeforeunload = HandleOnClose;


    function HandleOnClose(e) {
    var ev=(!e)?window.event:e;

    if(ev.clientX <0 || ev.clientY <0)
    {
    //prompt a message
    }
    else
    {
    return false;
    }
    }

    But this event is firing when i click on refresh button or navigate to other page also.

    Please help me out on this issue. You mail to my id: suhas.suhi@gmail.com

    Thanks in Advance,
    Suhas

    ReplyDelete
  7. hello avinash sir

    sir may u tell me how to get source code from setup file which is already built.plz tell me wt should i do?

    ReplyDelete
    Replies
    1. Install Your Software

      Go dir where exe is Installed

      and Use Decomplier example Red Gate Disassembler .net

































      Delete