PictureContentControl 不接受权限不足的图像 属性
PictureContentControl does not accept Image property with insufficient permissions
我正在开发一个 vsto-word 插件,并将远程图像插入到 picturecontentcontrol 中的 word 文档中。
一切正常,除了登录用户连接到远程登录域的机器。
我没有得到有关该错误的任何信息。它只是停止执行..
图像和一个空的内容控件被插入到 word 文档中,但是作为 两个对象 ,因此内容控件没有使用它的图像 属性。
这也是代码刚刚停止执行的地方:
public void resultImage(Result r, Dictionary<string, string> wizard)
{
if (this.hasSelection())
{
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(getCCRange(), this.getRandomControlName());
picture.LockContents = false;
toggleActiveCCs(false);
picture.Title = truncateCCTitle(r.title);
picture.Tag = getWizardString(wizard, r.arrange);
try {
Image img = Fetcher.getImage(r.data)
picture.Image = img;
}
catch (Exception e) {
Log.alert(e.Message);
}
afterInsert(picture.Range);
}
}
现在,我使用一个临时文件来存储图像,因为我想知道是否非管理员用户可能没有对内存的写入权限...
我还使用一个临时文件(带有 html)插入一个 table,它工作正常,也作为受限域访问用户......所以我想这也应该适用于图像!?
我尝试了很多东西,包括:
- 使用 StreamReader 和 Memory 流制作图像
- 锁定的 ContentControls 有类似的行为,只是停止工作,所以我确保它们都已解锁
- 正在传输 base64 编码的图像,也有内存流...但这里也一样...
我也在 MSDN
上问过这个问题
更新 X:
我确定了错误,它是 hresult 0x80004005(E_FAIL:未指定的故障)并没有多大帮助......该死的。
堆栈跟踪:
Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName,
Object& LinkToFile, Object& SaveWithDocument, Object& Range) at
Microsoft.Office.Tools.Word.PictureContentControlImpl.SetImage(Image
image) at
Microsoft.Office.Tools.Word.PictureContentControlImpl.set_Image(Image
value) at XXX.ThisAddIn.resultImage(Result r,
Dictionary`2 wizard)
这绝对是一个权限问题,我怎样才能check/set适当的权限..?!!
我试图尽可能接近您在问题中使用的缺失代码部分。错误肯定是这些缺失部分之一造成的(获取Range,获取Image甚至插入后的部分)
因此,在独立的 Office 插件中采用尽可能多的代码确实工作正常:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var vstodocument = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.Documents.Add());
vstodocument.Paragraphs[1].Range.InsertParagraphBefore();
PictureContentControl picture = vstodocument.Controls.AddPictureContentControl(vstodocument.Paragraphs[1].Range, "pictureControl2");
picture.LockContents = false;
picture.Title = "Title";
picture.Tag = "Tag";
try
{
// Before running put picture.bmp in C:\Users\<user>\Pictures
string imagePath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\picture.bmp";
System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(imagePath, true);
picture.Image = bitmap1;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
所以尝试隔离各个部分,看看是否有任何 return 出乎意料的事情...
我找到了一个简单的解决方案...它也适用于此域登录机器..
只需将一个内联形状添加到一个范围,并使内容控件超出此范围,例如:
Word.Range rng = getCCRange();
string tempPath = Fetcher.getImage(r.data);
rng.InlineShapes.AddPicture(tempPath);
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(rng, this.getRandomControlName());
我正在开发一个 vsto-word 插件,并将远程图像插入到 picturecontentcontrol 中的 word 文档中。
一切正常,除了登录用户连接到远程登录域的机器。
我没有得到有关该错误的任何信息。它只是停止执行.. 图像和一个空的内容控件被插入到 word 文档中,但是作为 两个对象 ,因此内容控件没有使用它的图像 属性。 这也是代码刚刚停止执行的地方:
public void resultImage(Result r, Dictionary<string, string> wizard)
{
if (this.hasSelection())
{
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(getCCRange(), this.getRandomControlName());
picture.LockContents = false;
toggleActiveCCs(false);
picture.Title = truncateCCTitle(r.title);
picture.Tag = getWizardString(wizard, r.arrange);
try {
Image img = Fetcher.getImage(r.data)
picture.Image = img;
}
catch (Exception e) {
Log.alert(e.Message);
}
afterInsert(picture.Range);
}
}
现在,我使用一个临时文件来存储图像,因为我想知道是否非管理员用户可能没有对内存的写入权限... 我还使用一个临时文件(带有 html)插入一个 table,它工作正常,也作为受限域访问用户......所以我想这也应该适用于图像!?
我尝试了很多东西,包括:
- 使用 StreamReader 和 Memory 流制作图像
- 锁定的 ContentControls 有类似的行为,只是停止工作,所以我确保它们都已解锁
- 正在传输 base64 编码的图像,也有内存流...但这里也一样...
我也在 MSDN
上问过这个问题更新 X: 我确定了错误,它是 hresult 0x80004005(E_FAIL:未指定的故障)并没有多大帮助......该死的。
堆栈跟踪:
Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName, Object& LinkToFile, Object& SaveWithDocument, Object& Range) at Microsoft.Office.Tools.Word.PictureContentControlImpl.SetImage(Image image) at Microsoft.Office.Tools.Word.PictureContentControlImpl.set_Image(Image value) at XXX.ThisAddIn.resultImage(Result r, Dictionary`2 wizard)
这绝对是一个权限问题,我怎样才能check/set适当的权限..?!!
我试图尽可能接近您在问题中使用的缺失代码部分。错误肯定是这些缺失部分之一造成的(获取Range,获取Image甚至插入后的部分)
因此,在独立的 Office 插件中采用尽可能多的代码确实工作正常:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var vstodocument = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.Documents.Add());
vstodocument.Paragraphs[1].Range.InsertParagraphBefore();
PictureContentControl picture = vstodocument.Controls.AddPictureContentControl(vstodocument.Paragraphs[1].Range, "pictureControl2");
picture.LockContents = false;
picture.Title = "Title";
picture.Tag = "Tag";
try
{
// Before running put picture.bmp in C:\Users\<user>\Pictures
string imagePath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\picture.bmp";
System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(imagePath, true);
picture.Image = bitmap1;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
所以尝试隔离各个部分,看看是否有任何 return 出乎意料的事情...
我找到了一个简单的解决方案...它也适用于此域登录机器.. 只需将一个内联形状添加到一个范围,并使内容控件超出此范围,例如:
Word.Range rng = getCCRange();
string tempPath = Fetcher.getImage(r.data);
rng.InlineShapes.AddPicture(tempPath);
PictureContentControl picture = getVSTODocument().Controls.AddPictureContentControl(rng, this.getRandomControlName());