在下面的代码中,文件保存在项目的debug文件夹中,我想将文件存储在通用指定文件夹下的appdata文件夹中!
AViewModel vm = DataContext as AViewModel;
var table = vm.FileSelectedItem;
if (table != null)
{
var filename = System.IO.Path.GetTempFileName();
File.WriteAllBytes(table.FileTitle, table.Data);
Process prc = new Process();
prc.StartInfo.FileName = table.FileTitle;
prc.Start();
}
//table.FileTitle is the name of the file stored in the db
// eg:(test1.docx, test2.pdf, test3.txt, test4.xlsx)
//table.Data is public byte[] Data { get; set; } property
// which stores the files coming from the db.
Run Code Online (Sandbox Code Playgroud)
我正在看GetFolderPath并尝试这样的事情
System.IO.Path.GetTempFileName(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
Run Code Online (Sandbox Code Playgroud)
谢谢你的回复!
GetTempFileName返回用户临时路径中文件的完整路径.您无法使用它在特定文件夹中创建文件.
鉴于你想要存储在AppData文件夹中,也许你会更喜欢以下内容:
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "YourCompany\\YourProduct\\Output");
var filename = Path.Combine(path, table.FileTitle);
File.WriteAllBytes(filename, table.Data);
Process.Start(filename);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
534 次 |
| 最近记录: |