动态构建System.IO.File目标 [英] Build System.IO.File Target dynamically

查看:92
本文介绍了动态构建System.IO.File目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有以下代码可以正常工作。我想要做的是动态构建Testauto.txt的实际文件名。如何为此字符串包含唯一的文件名?....我尝试将此字符串与唯一的
文件名连接起来是不成功的。

I have the following code that works fine. What I would like to do is build the actual file name of Testauto.txt dynamically. How can I include a unique file name for this string?.... I have been unsuccessful with trying to concatenate this string with unique file name..

在此先感谢 - Dan

Thanks in Advance - Dan

            System.IO.File.WriteAllText(@"c:\Users\BillJ\OneDrive\KML\Testauto.txt", KMLFile);

推荐答案

            // create a new temp file
            var tempFile = System.IO.Path.GetTempFileName();

            // get just the generated file name 
            var fileName = System.IO.Path.GetFileName(tempFile);

            // Remove some hard coding @"c:\Users\BillJ\OneDrive\KML\Testauto.txt"
            var destination = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "OneDrive", "KML", fileName);

            // move temp file
            System.IO.File.Move(tempFile, destination);

            // write data
            System.IO.File.WriteAllText(destination, KMLFile);





这篇关于动态构建System.IO.File目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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