如何创建与C#应用程序数据文件夹 [英] How to create appdata folder with C#

查看:233
本文介绍了如何创建与C#应用程序数据文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我不知道如何键入这一切如此忍受我请。

Well, I don't know how to type all this so bear with me please.

这是超越我,我仍然在C#对于新手。基本上,我需要在运行该程序的当前用户的漫游应用程序数据创建一个文件夹。我还需要访问应用程序中的数据部分的另一个文件夹,然后在我创建的应用程序数据文件夹中的文件副本替换文件。

This is beyond me, I'm still a newb at C#. I basically need to create a folder in the roaming application data of the current user running the program. I also need to access another folder in the application data section and then replace a file with a copy of the file in the application data folder I had created.

推荐答案

前两道很简单

// The folder for the roaming current user 
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

// Combine the base folder with your specific folder....
string specificFolder = Path.Combine(folder, "YourSpecificFolder");

// Check if folder exists and if not, create it
if(!Directory.Exists(specificFolder)) 
    Directory.CreateDirectory(specificFolder);

在最后一关是不明确的,你必须复制的文件。结果
但是,假设你已经称为文件

In the last pass is not clear where you have the file to copy.
However, supposing that you have a file called

string file = @"C:\program files\myapp\file.txt";
File.Copy(file. Path.Combine(specificFolder, Path.GetFileName(file));

MSDN链接:

MSDN links:

Path类结果
<一href=\"http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx\">Environment.SpecialFolder枚举结果
File.Copy方法

这篇关于如何创建与C#应用程序数据文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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