用文件名中的日期时间保存文件 [英] Saving a file with the datetime in the file name

查看:113
本文介绍了用文件名中的日期时间保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件名中包含日期时间的文件写入特定位置.写入文件后,我需要向用户提示另存为框.但是,当程序尝试查找新创建的文件时,由于日期时间不匹配而无法找到.

我知道它为什么这样做,我只是想不通如何解决它.我尝试使用变量,但似乎无法正确使用它.

预先感谢您提供任何建议或示例.

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();

推荐答案

也许您可以将文件名存储在会话变量中并传递.

像这样的东西:

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.


这篇关于用文件名中的日期时间保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆