Re: Saving rtf file.

  •  06-20-2006, 9:44 AM

    Re: Saving rtf file.

    I got it working.  I had to save the file on the server first, then initiate the download to the client machine.  If anyone is interested, it looks like this (I haven't gotten to deleting the temp file yet):

    private void Editor1_PostBackCommand(object sender, System.Web.UI.WebControls.CommandEventArgs e)
      {
       if(string.Compare(e.CommandName,"Save",true)==0)
       {
        Random rand = new Random();
        int randnum = rand.Next();
        String fileName;
        fileName = "PUT FILE PATH HERE" + randnum.ToString() + ".rtf";
        Editor1.SaveRTF(fileName);
        FileInfo fInfo = new FileInfo(fileName);
        long numBytes = fInfo.Length;
        FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fStream);
        byte [] data = br.ReadBytes((int)numBytes);
        Response.AddHeader("Content-Disposition", "attachment; filename=cute.rtf");
        Response.ContentType = "application/rtf";
        Response.Clear();
        Response.Buffer = true;
        Response.BinaryWrite(data);
        Response.End();
        br.Close();
        fStream.Close();
       }
      }
View Complete Thread