在 Word 2016 中从 Imanage 打开文档
Opening a document from Imanage in Word 2016
我正在尝试在临时测试应用程序(用于调试)中打开 MS Word 中的 Imanage 文档,以便稍后复制到 ActiveX 控件项目中。弹出的错误是:
Exception thrown at 0x7618851A (msvcrt.dll) in w3wp.exe: 0xC0000005: Access >violation reading location 0x09801000.
If there is a handler for this exception, the program may be safely continued.
错误发生在 运行 行 cmd.Execute 时,我不确定为什么会收到错误。
using IManage;
using IMANEXTLib;
using System;
namespace WebApplication3
{
public partial class WebForm2 : System.Web.UI.Page
{
IManDatabase imanagedatabase;
IManDMS myDMS = new ManDMSClass();
protected void Page_Load(object sender, EventArgs e)
{
openImanageDoc("docNumber", "versionNumber", "server", "database", ReadOnly);
}
public void imanageLogin(string server, string database)
{
try
{
IManSession session = myDMS.Sessions.Add(server);
IManWorkArea oWorkArea = session.WorkArea;
session.TrustedLogin();
foreach (IManDatabase dbase in session.Databases)
{
if (dbase.Name == database)
{
imanagedatabase = dbase;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
public void openImanageDoc(string docNo, string versionNo, string server, string database, bool isReadOnly = true)
{
IManDocument doc;
try
{
imanageLogin(server, database);
int iDocNo = int.Parse(docNo);
int iVersion = int.Parse(versionNo);
doc = imanagedatabase.GetDocument(iDocNo, iVersion);
openNRTDocument(ref doc, isReadOnly);
imanagedatabase.Session.Logout();
myDMS.Close();
}
catch (Exception Ex)
{
imanagedatabase.Session.Logout();
throw Ex;
}
finally
{
imanagedatabase = null;
myDMS = null;
}
}
public void openNRTDocument(ref IManDocument nrtDocument, Boolean isReadonly)
{
OpenCmd cmd = new OpenCmd();
ContextItems objContextItems = new ContextItems();
objContextItems.Add("NRTDMS", myDMS);
objContextItems.Add("SelectedNRTDocuments", new[] { (NRTDocument)nrtDocument.LatestVersion });
objContextItems.Add("IManExt.OpenCmd.Integration", false);
objContextItems.Add("IManExt.OpenCmd.NoCmdUI", true);
cmd.Initialize(objContextItems);
cmd.Update();
cmd.Execute();
}
}
}
由于错误的性质,我假设这是一个配置问题而不是代码错误,尽管我可能是完全错误的,因为我是编程新手。
我发现 w3wp.exe 是由应用程序池创建的 IIS 工作进程,但除此之外我不知道数字代码代表什么。非常感谢任何帮助或建议。
错误是由 OpenCmd 实例引起的,因为它很可能试图访问本地注册表设置等资源。在 Web 应用程序中不可能这样做,除非您将代码托管在专有技术中,例如 ActiveX(特定于 Internet Explorer)
实际上,您在这里使用OpenCmd并不合适。这些类型的命令(iManage "ICommand" 实现)旨在用于安装了 iManage FileSite 或 DeskSite 客户端的常规 Windows 应用程序。这些命令都是所谓的可扩展性 COM 库(iManExt.dll、iManExt2.dll 等)的一部分,不应在 Web 应用程序中使用,或至少谨慎使用,因为它们可能会不恰当地尝试访问注册表,如您所见,甚至可能显示输入 Win32 对话框。
对于 Web 应用程序,您应该将自己限制在低级 iManage COM 库 (IManage.dll)。这实际上是 iManage 自己用自己的 WorkSite Web 应用程序所做的
可能你应该做的是用这样的东西替换你的 openNRTDocument 方法:
// create a temporary file on your web server..
var filePath = Path.GetTempFileName();
// fetch a copy of the iManage document and save to the temporary file location
doc.GetCopy(filePath, imGetCopyOptions.imNativeFormat);
在 MVC 网络应用程序中,您只需 return 一个 FileContentResult,如下所示:
// read entire document as a byte array
var docContent = File.ReadAllBytes(filePath);
// delete temporary copy of file
File.Delete(filePath);
// return byte stream to web client
return File(stream, MediaTypeNames.Application.Octet, fileName);
在 Web 窗体应用程序中,您可以这样做:
// set content disposition as appropriate - here example is for Word DOCX files
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
// write file to HTTP content output stream
Response.WriteFile(filePath);
Response.End();
我正在尝试在临时测试应用程序(用于调试)中打开 MS Word 中的 Imanage 文档,以便稍后复制到 ActiveX 控件项目中。弹出的错误是:
Exception thrown at 0x7618851A (msvcrt.dll) in w3wp.exe: 0xC0000005: Access >violation reading location 0x09801000.
If there is a handler for this exception, the program may be safely continued.
错误发生在 运行 行 cmd.Execute 时,我不确定为什么会收到错误。
using IManage;
using IMANEXTLib;
using System;
namespace WebApplication3
{
public partial class WebForm2 : System.Web.UI.Page
{
IManDatabase imanagedatabase;
IManDMS myDMS = new ManDMSClass();
protected void Page_Load(object sender, EventArgs e)
{
openImanageDoc("docNumber", "versionNumber", "server", "database", ReadOnly);
}
public void imanageLogin(string server, string database)
{
try
{
IManSession session = myDMS.Sessions.Add(server);
IManWorkArea oWorkArea = session.WorkArea;
session.TrustedLogin();
foreach (IManDatabase dbase in session.Databases)
{
if (dbase.Name == database)
{
imanagedatabase = dbase;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
public void openImanageDoc(string docNo, string versionNo, string server, string database, bool isReadOnly = true)
{
IManDocument doc;
try
{
imanageLogin(server, database);
int iDocNo = int.Parse(docNo);
int iVersion = int.Parse(versionNo);
doc = imanagedatabase.GetDocument(iDocNo, iVersion);
openNRTDocument(ref doc, isReadOnly);
imanagedatabase.Session.Logout();
myDMS.Close();
}
catch (Exception Ex)
{
imanagedatabase.Session.Logout();
throw Ex;
}
finally
{
imanagedatabase = null;
myDMS = null;
}
}
public void openNRTDocument(ref IManDocument nrtDocument, Boolean isReadonly)
{
OpenCmd cmd = new OpenCmd();
ContextItems objContextItems = new ContextItems();
objContextItems.Add("NRTDMS", myDMS);
objContextItems.Add("SelectedNRTDocuments", new[] { (NRTDocument)nrtDocument.LatestVersion });
objContextItems.Add("IManExt.OpenCmd.Integration", false);
objContextItems.Add("IManExt.OpenCmd.NoCmdUI", true);
cmd.Initialize(objContextItems);
cmd.Update();
cmd.Execute();
}
}
}
由于错误的性质,我假设这是一个配置问题而不是代码错误,尽管我可能是完全错误的,因为我是编程新手。
我发现 w3wp.exe 是由应用程序池创建的 IIS 工作进程,但除此之外我不知道数字代码代表什么。非常感谢任何帮助或建议。
错误是由 OpenCmd 实例引起的,因为它很可能试图访问本地注册表设置等资源。在 Web 应用程序中不可能这样做,除非您将代码托管在专有技术中,例如 ActiveX(特定于 Internet Explorer)
实际上,您在这里使用OpenCmd并不合适。这些类型的命令(iManage "ICommand" 实现)旨在用于安装了 iManage FileSite 或 DeskSite 客户端的常规 Windows 应用程序。这些命令都是所谓的可扩展性 COM 库(iManExt.dll、iManExt2.dll 等)的一部分,不应在 Web 应用程序中使用,或至少谨慎使用,因为它们可能会不恰当地尝试访问注册表,如您所见,甚至可能显示输入 Win32 对话框。
对于 Web 应用程序,您应该将自己限制在低级 iManage COM 库 (IManage.dll)。这实际上是 iManage 自己用自己的 WorkSite Web 应用程序所做的
可能你应该做的是用这样的东西替换你的 openNRTDocument 方法:
// create a temporary file on your web server..
var filePath = Path.GetTempFileName();
// fetch a copy of the iManage document and save to the temporary file location
doc.GetCopy(filePath, imGetCopyOptions.imNativeFormat);
在 MVC 网络应用程序中,您只需 return 一个 FileContentResult,如下所示:
// read entire document as a byte array
var docContent = File.ReadAllBytes(filePath);
// delete temporary copy of file
File.Delete(filePath);
// return byte stream to web client
return File(stream, MediaTypeNames.Application.Octet, fileName);
在 Web 窗体应用程序中,您可以这样做:
// set content disposition as appropriate - here example is for Word DOCX files
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
// write file to HTTP content output stream
Response.WriteFile(filePath);
Response.End();