Click here to Skip to main content
13,248,927 members (43,093 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am writing a file to a specific location with the datetime included in the file name. After the file is written, I am needing to prompt a save as box to the user. However, when the program tries to find the newly created file, it is unable to because the datetimes do not match.

I know why it is doing that, I just can't figure out how get around it. I have tried using variables but just can't seem to get it right.

Thank you in advance for any advice or examples.

if (dr[12].ToString().Contains("99|"))
                            {
                                StreamWriter sw = new StreamWriter(@"C:\inetpub\temp\99-Authorize.Net - " + date1 + " @ " + date2 + ".ach");//
                                if (dr[0].ToString() != "2")
                                {
                                    if (dr[9].ToString() != "Total Amount")
                                    {
                                        sw.Write("6                            ");
                                        sw.Write(dr[9].ToString().Replace(".", "").Replace(",", "").PadLeft(10, '0'));
                                        sw.Write((dr[12].ToString()).PadRight(15, ' '));
                                        sw.Write((dr[13].ToString() + " " + dr[14].ToString()).PadRight(40));
                                        sw.Write(sw.NewLine);
                                    }
                                }
                                sw.Write("9");
                                sw.Write(sw.NewLine);
                                sw.Close();


string fileName2 = ("99-Authorize.Net - " + date1 + " @ " + date2 + ".ach");//
        string filePath2 = (@"C:\inetpub\temp\99-Authorize.Net" + date1 + " @ " + date2 + ".ach");
 
        Response.Clear();
        Response.AppendHeader("content-disposition",
        "attachment; filename=" + fileName2);
        Response.ContentType = "application/octet-stream";
        Response.WriteFile(filePath2);
        Response.Flush();
        Response.End();
Posted 12-Jun-12 6:00am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Perhaps you could store the file name in a session variable and pass that along.

Something like:

string filename = "99-Authorize.Net - " + date1 + " @ " + date2 + ".ach";
Session.Add("DatedFileName", filename);


You could then use this with:

filename = Session("DateFileName");


Very simplistic but might suit your need.
  Permalink  
Comments
losmac 12-Jun-12 13:02pm
   
Nice! +5
richcb 12-Jun-12 14:35pm
   
Thank you, that is what I was trying to do!
Jani Giannoudis 13-Jun-12 3:03am
   
Depending oh the culture, the DateTime.ToString can be conflicting for a file name. You may use string filename = string.Format( "99-Authorize.Net - {0} @ {1}", date1.ToString( "yyyyMMddHHmmss" ), date2.ToString( "yyyyMMddHHmmss" ) );
mark merrens 13-Jun-12 10:24am
   
Good addition.
richcb 14-Jun-12 9:35am
   
That is better code than what I have implemented. Thank you for the insight.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100