假设我的文件路径为:
C:\Users\my_name\Desktop\my_project\bin\debug\my_project.exe
如何在OpenFileDialog
中获取以下文件路径?
C:\Users\my_name\Desktop\my_project\
修改
我尝试了以下内容..
var path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent?.ToString();
var path = Assembly.GetExecutingAssembly().CodeBase;
但两者都返回不正确的值。
答案 0 :(得分:1)
您可以使用以下逻辑:
DirectoryInfo Di = Directory.GetParent(@"C:\Users\my_name\Desktop\my_project\bin\debug\my_project.exe");
// Which will give you the debug folder
int DirectoryLevel = 3;
for (int i = 1; i < DirectoryLevel; i++)
{
Di = Di.Parent;
// Which will give you the bin fodler when i =1
// Which will give you the my_project folder when i =2
}
string currentDirectory = Di.FullName; // Give the path
答案 1 :(得分:0)
您可以使用此代码
//In my CollectionView Controller.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "DetailsView")
{
if let vc:DetailsViewController = segue.destinationViewController as? DetailsViewController
{
vc.detailsString = self.description
vc.lineString = self.subText
vc.startTimeString = self.formatted_time
}
}
}
//DetailsViewController
import UIKit
class DetailsViewController: UIViewController {
@IBOutlet var startTime: UILabel!
@IBOutlet var line: UILabel!
@IBOutlet var details: UILabel!
var startTimeString: String?
var lineString: String?
var detailsString: String?
override func viewDidLoad() {
super.viewDidLoad()
startTime.text = tmpStartTimeString
line.text = tmpLineString
details.text = tmpDetailsString
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}