Temporary Flat Files

Discussion in 'ASP .Net Web Services' started by Thom Little, Mar 7, 2005.

  1. Thom Little

    Thom Little Guest

    I have an ASP 3 application that I am converting to and improving with
    ASP.NET. This application creates two temporary flat files and appends them
    to an SMTP mail message that it then sends.

    Can I use the Cache in ASP.NET for a similar purpose instead of writing to
    and reading from disk on the server? Is there a better approach?

    Is there an example or description that you can recommend?

    --
    -- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
    --
    Thom Little, Mar 7, 2005
    #1
    1. Advertising

  2. The following article contains code to create attachments, you could perhaps
    modify it to use a stream instead.

    http://www.eggheadcafe.com/articles/20030316.asp

    I am guessing there is code somewhere that writes these flat files. So,
    instead of writing the files, pass the stream to the above code. Hope that
    helps.

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Thom Little" <> wrote in message
    news:...
    > I have an ASP 3 application that I am converting to and improving with
    > ASP.NET. This application creates two temporary flat files and appends

    them
    > to an SMTP mail message that it then sends.
    >
    > Can I use the Cache in ASP.NET for a similar purpose instead of writing to
    > and reading from disk on the server? Is there a better approach?
    >
    > Is there an example or description that you can recommend?
    >
    > --
    > -- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
    > --
    >
    >
    >
    Manohar Kamath, Mar 7, 2005
    #2
    1. Advertising

  3. Thom Little

    Thom Little Guest

    That is a very interesting article and probably helpful for solving a larger
    problem that I have.

    I currently have the revised application written and tested to use Smtp. It
    is invoked with a form from any HTTP page. The remaining issue is to create
    and attach two files. I am looking for an example that allows me to attach
    "files" that are not physically resident on disk. Perhaps this is a
    capability provided by the Cache?

    The reason is that writing them to disk makes it necessary to have a
    dedicated folder (temp) that has permissions adjusted for ASP.NET access.
    This makes it cumbersome to setup when moved to a server under some else's
    control.

    --
    -- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
    --

    "Manohar Kamath" <> wrote in message
    news:%...
    > The following article contains code to create attachments, you could
    > perhaps
    > modify it to use a stream instead.
    >
    > http://www.eggheadcafe.com/articles/20030316.asp
    >
    > I am guessing there is code somewhere that writes these flat files. So,
    > instead of writing the files, pass the stream to the above code. Hope that
    > helps.
    >
    > --
    > Manohar Kamath
    > Editor, .netWire
    > www.dotnetwire.com
    Thom Little, Mar 7, 2005
    #3
  4. Thom Little

    [MSFT] Guest

    Hello Thom,

    The object in ASP.NET cache cannot be used as actual file for amail
    attachment. I think Manohar's suggestion is the right way to resolve the
    problem. You can take a look at following code in the sample he recommended:

    MailAttachment a = o as MailAttachment;
    byte[] binaryData;
    if(a!=null)
    {
    FileInfo f = new FileInfo(a.Filename);
    sb.Append("--unique-boundary-1\r\n");
    sb.Append("Content-Type: application/octet-stream; file=" + f.Name +
    "\r\n");
    sb.Append("Content-Transfer-Encoding: base64\r\n");
    sb.Append("Content-Disposition: attachment; filename=" + f.Name + "\r\n");
    sb.Append("\r\n");
    FileStream fs = f.OpenRead();
    binaryData = new Byte[fs.Length];
    long bytesRead = fs.Read(binaryData, 0, (int)fs.Length);
    fs.Close();
    string base64String = System.Convert.ToBase64String(binaryData,
    0,binaryData.Length);

    ...

    Above code add an attachment to the mail and data is in the byte array.
    Based on the sample, you can load your data in a byte array or stream, and
    then add to the mail.

    Luke
    [MSFT], Mar 8, 2005
    #4
    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. Homer
    Replies:
    230
    Views:
    10,692
    Roedy Green
    May 1, 2006
  2. Replies:
    5
    Views:
    738
    Juan T. Llibre
    Jan 26, 2007
  3. Replies:
    1
    Views:
    658
    bruce barker
    Feb 22, 2007
  4. Replies:
    7
    Views:
    3,179
    James Kanze
    Feb 12, 2008
  5. AAaron123
    Replies:
    3
    Views:
    559
    AAaron123
    Nov 4, 2008
Loading...

Share This Page