Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have created a WindowsApp.exe under Application\Setup folder. Now I want to create a Database under Application\Database folder from WindowsApp.exe
What should be the path given to the filename here?
try
Path.Combine(Environment.CurrentDirectory, "Database\\db1.mdb")
Edit
since you want the parent folder you can go up one folder by doing
Path.Combine(Environment.CurrentDirectory.Substring(Environment.CurrentDirectory.LastIndexOf("\\")), "Database\\db1.mdb")
Edit 2
if you want the Application folder even if its N times above the current folder then you can reach it by doing this
var index = Environment.CurrentDirectory.IndexOf(Environment.CurrentDirectory.IndexOf("ApplicationRootFolderName"),"\\")
var AppRootPath = Environment.CurrentDirectory.Substring(0,index);
Edit 3
As mentioned by Michael its better to get the parent folder using this way
Directory.GetParent(Environment.CurrentDirectory).FullName
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello I have multiple text files in one location and they have names as shown below:-
A_L_PRTD_021345.txt , A_L_PRTD_432124 and so on...
I want to append the contents into single file and want to rename the single file as L_PRTD_Currentdate>.txt
How is it possible?
Can you please show some code for it?
First read each file using File.ReadAllLines(fileName) ;
Then create a single file and append the contents of other files in it
string[] contents1 = File.ReadAllLines(fileName1) ;
string[] contents2 = File.ReadAllLines(fileName2) ;
File.Create(newFileNameHere) ;
File.WriteAllLines(newFileNameHere, contents1) ;
File.AppendAllLines(newFileNameHere, contents2) ;
and so on ...
Check the following documentation of the functions, if you need help:-
http://msdn.microsoft.com/en-us/library/92e05ft3(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/dd383691(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/s2tte0y1(v=vs.110).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have property which holds filenameOnly without extension.
string fileNameOnly = "myFileName";
now I want to perform multiple checks on selected location for example c:\ for existed filename+fileextension (.jpg, .png, .gif, .bmp)
so, if c:\myFileName.jpg exist than assign that value to string filename="myFileName.jpg" variable.
what is the best and quickest way to do this?
Try something like this to get an array of files that fit your pattern:
string[] files = Directory.GetFiles(
DirectoryPath,
String.Format("{0}.*", fileNameOnly));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working on a program and to avoid complication I need to parse a given string variable to be a DirectoryInfo.
I was wondering if it were possible to parse a string to a DirectoryInfo.
If it is, how does one go about doing that?
Thanks
DirectoryInfo di = new DirectoryInfo(string);
MSDN, linked above, provides you the exceptions in case the string is invalid. Note: this is NOT if the directory exists. MSDN also makes note of this in the Remarks. You must then do:
if(di.Exists)
Well, it's not parsing, but the constructor for DirectoryInfo takes the path as a string:
DirectoryInfo di = new DirectoryInfo(#"c:\MyDir");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I use this code blow in .NET. It works fine. The problem is that I want this audio to play in the root of the website. What changes should I make for this? Thanks
var sample= new System.Windows.Media.MediaPlayer();
sample.Open(new System.Uri( #"D:\voices\1.wav");
sample.Play();
In a web application, this might look something like this:
sample.Open(new System.Uri(Server.MapPath("~/") + #"\voices\1.wav");
I say might because that all depends on whether or not the voices folder exists in the root of the website. Additionally, you should probably leverage Path.Combine instead:
var path = Path.Combine(Server.MapPath("~/"), "voices", "1.wav");
sample.Open(path);
Finally, I don't know what sample is, but the Open method may not work in a website. I'm making the assumption you know what Open does and whether or not it can work in a website.
Use server.mappath("~/") <- that's the filesystem root for your website.
dim path as string = server.mappath("~/") & "/voices/1.wav"
Note that backslashes, for filesystem path, not URI.
Hope it helps.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following path...
'X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\'
I want to split it at the directory 'Assets' and end up with...
'Assets\Models\FullBuilding\Materials\'
The directory 'Assets' will not always be in the same place in the path. How can I do this? Thanks.
Lets say your string is
string completePath = "X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\";
string subPath = completePath.subString(completePath.IndexOf(#"Assets\"));
Please note that if your path contains multiple instances of Assests it will substring from first instance of Asset.
you can use path.IndexOf, you can use the str.SubString(str.IndexOf("\assetse")), you can do alot of things. playing with string is kinda fun...
most of the things you want to do with strings you can find on google anyway