我想打开位置文件,并在mac浏览器中选择文件,ubuntu从monodevelop。 这个代码在Windows工作(在Mac和Ubuntu无法正常工作):如何在monodevelop gtk#中打开文件位置或打开文件夹位置?
System.Diagnostics.Process.Start("explorer.exe", "/select, " + fileaddress);
我想打开位置文件,并在mac浏览器中选择文件,ubuntu从monodevelop。 这个代码在Windows工作(在Mac和Ubuntu无法正常工作):如何在monodevelop gtk#中打开文件位置或打开文件夹位置?
System.Diagnostics.Process.Start("explorer.exe", "/select, " + fileaddress);
使用Process.Start()
你绕过.NET框架,进入你正在运行到平台上,执行任意程序。
在Windows上,您想要打开Windows资源管理器,在Mac上您要打开Finder,而在Ubuntu上,它简称为文件浏览器。
在框架中没有Environment.OpenFileBrowser(string path)
方法,所以您将将不得不让您的程序确定它运行在哪个平台上,并打开approperiate文件查看器。
Dim dir_path As String = "/media/os/test"
' Windows path example: dir_path = "C:\test"
Process.Start("file://" & dir_path)
经过测试并在Ubuntu和Windows XP上工作。
不会选择文件,但它是一个很好的后备,我猜:) – Nyerguds
这个职位是有点老了,但希望这会帮助别人。
您正在调用操作系统特定的(WinBlows)方法。这将无法运行crossPlatform。
尝试的功能/方法内执行以下操作:
实施例 - 将点击事件内:
protected void OnOpen (object sender, EventArgs e)
{
using(FileChooserDialog chooser = new FileChooserDialog (null,"Select document to open...",
null, FileChooserAction.Open, "Open Selected File", ResponseType.Accept,
"Discard & Return to Main Page", ResponseType.Cancel)) {
if (chooser.Run() == (int)ResponseType.Accept) {
System.IO.StreamReader file = System.IO.File.OpenText (chooser.Filename);
/*Copy the contents to editableTxtView <- This is the Widget Name */
editableTxtView.Buffer.Text = file.ReadToEnd();
/* If you want to read the file into explorer, thunar, notepad, etc,
* you'll have to research that yourself */
//Close file - - KEEP IT CLEAN - - & deAllocated memory!!
file.Close();
}
}
}
该文件已经被复制到一个可编辑的(默认) 或只读(集属性pad)textviewer Gtk Widget。 从那里您应该能够按照您的选择操作它。
这是完全不相关的问题。这类问题通常是在你创建一些东西并将其保存为一个文件之后,你想让用户能够打开文件浏览器并跳转到新创建的文件,以便他们可以使用它来做某件事。 – Nyerguds
您可以使用Mac上的 '开放',像这样
System.Diagnostics.Process.Start("open", $"-R \"{File_Path_You_Wanna_Select}\"");
这里-R手段揭示,在Finder中,而不是打开选择。 要找到更多的用法打开,只需键入打开在终端。
我怎么找到一个例子? –
一个什么样的例子? – CodeCaster
在gtk中显示mac和ubuntu中的文件位置# –