'Copying vs creating a file using C#
We have a web service that creates a folder structure for our projects and as part of the this I need to create a text file that has the path to the project. I've created a template text file with a dummy path that I will replace when creating the file. e.g
//XXXXXXXX/projects/
Now the question is, what is the optimal way to create the file on a network share from my template and update the path? I think I have two options:
open template file, get content as a string, replace the xxxxxxxx and then create a new text file on the network share
copy the template file to the network share, open, get the content as a string, replace the xxxxxxxx and save back
Solution 1:[1]
I think this question is primarily opinion-based, but here goes:
I'd go for option #1, simply because (a) the two options are not that different and do not pose any significantly different technical "challenges", and (b) with option #1 you never run into the problem of having a file that points to an illegal path.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Roy Dictus |