我需要以编程方式从Visio中的Sharepoint打开文档。但是,当我浏览到网络文件夹,选择一个文件并点击打开,我 得到以下错误:C#OpenFileDialog:文件名,目录名称或卷标语法不正确
The filename, directory name, or volume label syntax is incorrect
当错误搜索,我发现了以下文件:https://msdn.microsoft.com/en-us/library/ms832054.aspx。所以我猜想文件名称包含非法字符。我尝试使用FileOk事件覆盖文件名的验证:
public void openFile() {
OpenFileDialog sf = new OpenFileDialog();
sf.FileOk += openFileDialog_FileOk;
if (sf.ShowDialog() == DialogResult.OK)
{
var app =(Microsoft.Office.Interop.Visio.Application)context.Application;
app.Documents.Open(sf.FileName);
}
}
private void openFileDialog_FileOk(object sender, CancelEventArgs e)
{
var sfd = sender as OpenFileDialog;
var file = new FileInfo(sfd.FileName);
if (file.Name.Contains('#'))
e.Cancel = true;
}
但事件不会触发。使用标准的Visio界面可以从Sharepoint打开文件,但文件对话框看起来有点不同:
我怎样才能获得类似的文件对话框?所以我的问题是:我如何以编程方式从Sharepoint(网络文件夹)打开Visio文档?
'发件人为SaveFileDialog'?不是'OpenFileDialog'? – apocalypse