Reputation: 117
I have a folder named Template in my solution. I want some files to be copied in to it and accessed from it. How can i set the path to that? Will this folder be there when i deploy the application?
does this work?
File.Move(@"DebriefReportTemplate.docx", @"~\Template\DebriefReportTemplate.docx");
Upvotes: 0
Views: 489
Reputation: 6406
You may use
string sourceFile = Path.GetDirectoryName(Application.ExecutablePath)+@"\Template\DebriefReportTemplate.docx";
string destinationFile = @"C:\DebriefReportTemplate.docx";
// To move a file or folder to a new location:
System.IO.File.Move(sourceFile, destinationFile);
References :
Upvotes: 0
Reputation: 2782
EDIT: This answer is for an ASP.NET application.
If Template folder (including its content) is part of the web project, the deployment should work automatically. If you want to add files to this folder at runtime, you can use
Server.MapPath(@"~\Template\DebriefReportTemplate.docx")
, but be careful, the web application usually runs under an identity which has limited access to the local resources.
The same thing applies if you have a Win app. What you need to do is to add the folder and the files to the project, as Content. You will need a setup project though.
Upvotes: 0
Reputation: 7457
If you are worried about the existence of the Template folder, you could just create it at some point in your code.
string path = System.IO.Path.Combine("", "Template");
System.IO.Directory.CreateDirectory(path);
and then move the file
File.Move(@"DebriefReportTemplate.docx", @"Template\DebriefReportTemplate.docx");
Upvotes: 0
Reputation: 10184
It won't be created unless you either build a setup/deployment project to create it at install time, or add code in your app to create it upon first invocation.
Upvotes: 1