Permission Problem writing to Disk in Asp.NET application

Discussion in 'ASP .Net' started by Lars Netzel, Mar 3, 2005.

  1. Lars Netzel

    Lars Netzel Guest

    Here's what I need to do:
    Due to a bug in Crystal Reports ExportToStream() method I can't stream a
    Crystal Reports directly to the client as PDF and I must must use the
    Export() and put the the PDF on disk first and stream to the client. That's
    just how it is.

    Question:
    So I need to let the aspx user have write permissions to disk.. NOT GOOD.
    How do I solve this? Can I somehow write the PDF to disk in another thread
    with other writes? OR are ther other ways around this?

    best regards
    /Lars Netzel
     
    Lars Netzel, Mar 3, 2005
    #1
    1. Advertising

  2. Lars

    Note : The code below is stripped from a asp.net project using a web
    service. This project would relay a binary file from an internal web server
    where Crystal reports is installed to an external web server. You will still
    need write permissions for the directory you want to save to

    You could try this, I hope It helps

    Stream fs =
    rep.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    byte[] binaryfile = StreamToBinary(fs);
    string docLocation = Server.MapPath(null) + @"\Docs\";
    SaveFileToServer(binaryfile,docLocation,"my.pdf",DateTime.Now);
    Response.Redirect("Docs/"+"my.pdf");

    public void SaveFileToServer(byte[] binaryFile, string docPath, string
    docName, DateTime fileModifiedDate)
    {
    Directory.CreateDirectory(docPath);
    MemoryStream m = new MemoryStream(binaryFile);
    FileStream f = new FileStream(docPath+docName,FileMode.Create);
    m.WriteTo(f);
    f.Close();
    m.Close();
    File.SetLastWriteTime(docPath+docName,fileModifiedDate);
    }

    public byte[] StreamToBinary(Stream fs)
    {
    Int32 i = Convert.ToInt32(fs.Length);
    byte[] b = new byte[fs.Length];
    fs.Read(b,0,i);
    fs.Close();
    }


    "Lars Netzel" <> wrote in message
    news:%...
    > Here's what I need to do:
    > Due to a bug in Crystal Reports ExportToStream() method I can't stream a
    > Crystal Reports directly to the client as PDF and I must must use the
    > Export() and put the the PDF on disk first and stream to the client.
    > That's just how it is.
    >
    > Question:
    > So I need to let the aspx user have write permissions to disk.. NOT GOOD.
    > How do I solve this? Can I somehow write the PDF to disk in another thread
    > with other writes? OR are ther other ways around this?
    >
    > best regards
    > /Lars Netzel
    >
     
    Kamal Vaghjiani, Mar 3, 2005
    #2
    1. Advertising

  3. Lars Netzel

    Lars Netzel Guest

    Thanks but I can't ExportToStream due to a bug with record and
    groupselections in the Crystal Reports Engine. so I can't use that code.

    I need to write to disk with other permisisons than the ASPNET user

    /Lars


    "Kamal Vaghjiani" <> wrote in message
    news:...
    > Lars
    >
    > Note : The code below is stripped from a asp.net project using a web
    > service. This project would relay a binary file from an internal web
    > server where Crystal reports is installed to an external web server. You
    > will still need write permissions for the directory you want to save to
    >
    > You could try this, I hope It helps
    >
    > Stream fs =
    > rep.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    > byte[] binaryfile = StreamToBinary(fs);
    > string docLocation = Server.MapPath(null) + @"\Docs\";
    > SaveFileToServer(binaryfile,docLocation,"my.pdf",DateTime.Now);
    > Response.Redirect("Docs/"+"my.pdf");
    >
    > public void SaveFileToServer(byte[] binaryFile, string docPath, string
    > docName, DateTime fileModifiedDate)
    > {
    > Directory.CreateDirectory(docPath);
    > MemoryStream m = new MemoryStream(binaryFile);
    > FileStream f = new FileStream(docPath+docName,FileMode.Create);
    > m.WriteTo(f);
    > f.Close();
    > m.Close();
    > File.SetLastWriteTime(docPath+docName,fileModifiedDate);
    > }
    >
    > public byte[] StreamToBinary(Stream fs)
    > {
    > Int32 i = Convert.ToInt32(fs.Length);
    > byte[] b = new byte[fs.Length];
    > fs.Read(b,0,i);
    > fs.Close();
    > }
    >
    >
    > "Lars Netzel" <> wrote in message
    > news:%...
    >> Here's what I need to do:
    >> Due to a bug in Crystal Reports ExportToStream() method I can't stream a
    >> Crystal Reports directly to the client as PDF and I must must use the
    >> Export() and put the the PDF on disk first and stream to the client.
    >> That's just how it is.
    >>
    >> Question:
    >> So I need to let the aspx user have write permissions to disk.. NOT GOOD.
    >> How do I solve this? Can I somehow write the PDF to disk in another
    >> thread with other writes? OR are ther other ways around this?
    >>
    >> best regards
    >> /Lars Netzel
    >>

    >
    >
     
    Lars Netzel, Mar 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    987
    Jas Shultz
    Dec 3, 2003
  2. =?Utf-8?B?TWlrYWVsIEd1c3RhZnNzb24=?=

    FileStream permission problem with asp.NET web application!

    =?Utf-8?B?TWlrYWVsIEd1c3RhZnNzb24=?=, May 26, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,906
    Guest
    May 28, 2004
  3. Loane Sharp
    Replies:
    2
    Views:
    588
    Loane Sharp
    Sep 14, 2005
  4. Replies:
    12
    Views:
    535
    santosh
    Nov 15, 2006
  5. Milop
    Replies:
    3
    Views:
    716
    Josma
    Aug 2, 2007
Loading...

Share This Page