Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DateTime
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 5: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 at 12-Jun-12 13:02pm
   
Nice! +5
richcb at 12-Jun-12 14:35pm
   
Thank you, that is what I was trying to do!
Jani Giannoudis at 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 at 13-Jun-12 10:24am
   
Good addition.
richcb at 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
0 Sergey Alexandrovich Kryukov 494
1 CPallini 325
2 OriginalGriff 225
3 George Jonsson 130
4 ChauhanAjay 104
0 OriginalGriff 6,464
1 Sergey Alexandrovich Kryukov 5,915
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2014
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