The goal of this p
Synthetic lethalit
In this article we
Q: Is there a way
Q: Find a value i
Introduction {#Sec
Q: Square root (s
Square Enix has an
If so, would you e
Inhibitory effect

Q: D3 force graph
package org.eclips
We use cookies to
In the early 1940'
/* ***** BEGIN LIC
We all know the st
This is a randomiz
Gmina Stary Targ
The present invent
Q: Is there a sta
Q: How to add a file from a specific directory to a folder that can be seen in a different program? I have this program here. I have the following code in the program: string filePath = @"C:\Users\Administrator\Desktop\Project 2\Files\files\File Name.pdf"; if (!File.Exists(filePath)) { try { using (FileStream fs = File.Create(filePath)) { fs.Close(); } } catch { throw new System.IO.IOException("File does not exist."); } } I was wondering if there is a way to make this the same directory on the other program so it will work if they put the folder in the same place? Thanks A: It's best to have absolute paths. If the two folders are in different places, you might use the Path.Combine method to combine them. Then, you need to give a full path (e.g., C:\Users\Administrator\Desktop\Project 2\Files\files\File Name.pdf) which might be confusing to your users. An alternative could be to use the Environment.GetFolderPath method, which returns the path of a specific folder. However, this is not a fixed path, but a variable that might be different every time. Therefore, if the folder path changes (e.g., the user deletes the folder or moves it), you can't expect the path to be the same. In short: Make sure the path uses absolute paths. If it doesn't matter where the path leads to, you can't use the Path.Combine method, since the folders aren't known in advance. Use the Environment.GetFolderPath method for more flexible paths. A: This should give you the full path to your executable file, where you need to add "..\Files\files\File Name.pdf": string location = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); This will give you the full path of the parent folder of the executable file: string currentFolder = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)); You could use either of those variables in your file creation. This link has a nice explanation. If this doesn't help, the parent folder must be the same: Note: If you're storing files in the same parent folder on multiple machines, then you will run into problems if you don't also save the parent folder name. For example, if I want to share files to two different computers, I have to make sure both computers have the same parent folder. A: If you're using FileStream you can use the constructor with a third parameter that takes the directory name. If you're using another method of writing a file you should be able to pass the directory in the call to that method. Creates a new FileStream object, associated with the specified file name, on the specified path in the file system. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, Path.Combine( directoryPath, fileName)); More information on the constructor of the FileStream class This code uses the System.IO.Directory class to read a file from a path you specify. Then it uses Path.Combine to create a new file using a different directory for the file. string filePath = @"C:\Users\Administrator\Desktop\Project 2\Files\files\File Name.pdf"; FileInfo fi = new FileInfo(filePath); string directoryPath = fi.Directory.FullName; string fullPath = Path.Combine(directoryPath, "File Name.pdf"); if (!File.Exists(fullPath)) { File.Copy(filePath, fullPath); } This code uses the Path.GetDirectoryName function to get the directory that the file is in. string filePath = @"C:\Users\Administrator\Desktop\Project 2\Files\files\File Name.pdf"; string directoryPath = Path.GetDirectoryName(filePath); If you're trying to access a directory path instead of a file then you'll want to use GetCurrentDirectory instead of GetDirectoryName. Gets the directory of the currently executing assembly If you want to find out what directory your file is being copied to you can use the code below. I'm not sure if this is what you are really looking for but if you know the name of your file you can find out the filepath using the code above. If you want to know where the copy operation is being executed you will have to run this in a thread then find out where that thread is and check the filepath. string filePath = @"C:\Users\Administrator\Desktop\Project 2\Files\files\File Name.pdf"; string directoryPath = Directory.GetCurrentDirectory(); using (StreamWriter sw = new StreamWriter("c:\\log.txt", true)) { sw.WriteLine("filepath: " + directoryPath + " fileName: " + filePath); sw.Close(); }