信息路径;使用代码访问具有域信任设置的本地文件

问题描述

我正在为我的公司创建一个表单。该表格只能离线使用(送货员出发前会使用它),它生成的数据将在晚上由机器人收集。

现在,因为我需要文件具有唯一的文件名(以便机器人可以识别它们),所以我不希望用户使用 save as。相反,我创建了一个带有代码的按钮。现在代码保存文件关闭应用程序。这有效,但仅当表单信任级别设置为 full 时才有效。

问题是,无法在公司的计算机上打开完全受信任的表单。所以我需要对 restricteddomain一个信任级别。其中域提供了最多的可能性。有没有办法做到这一点?单击按钮时出现以下错误

Request for the permission of type 'System.Security.Permissions.FileIOPermission,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089' Failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand,StackCrawlMark& stackMark,Boolean isPermSet)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccesspermission cap,StackCrawlMark& stackMark)
   at System.Security.CodeAccesspermission.Demand()
   at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access,String fullPath,Boolean checkForDuplicates,Boolean needFullPath)
   at System.IO.Directory.InternalGetCurrentDirectory(Boolean checkHost)
   at System.IO.Directory.GetCurrentDirectory()
   at coded.FormCode.CTRL1_5_Clicked(Object sender,ClickedEventArgs e)
   at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
   at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

我认为它说明 at System.IO.Directory.GetCurrentDirectory() 有问题,因为这是访问本地文件的第一行代码在这种情况下,它找到表单所在的地图)。但是,如果我更改此行并仅修复位置,它会抛出相同的错误但指向 this.SaveAs 行(如果我对此进行评论,它会将其抛出到 System.Environment.Exit(0);)。

我想我真的需要这段代码,因为我想不出另一种方法来保存文件而不强迫用户使用保存选项然后必须自己提供文件名。

非常感谢任何帮助。

我的按钮代码

using Microsoft.Office.InfoPath;
using System.Windows.Forms;
using mshtml;
using System;
using System.Xml;
using System.Xml.XPath;
//using System.IO;


namespace coded
{
    public partial class FormCode
    {
        
        public void InternalStartup()
        {
            ((ButtonEvent)EventManager.ControlEvents["CTRL1_5"]).Clicked += new ClickedEventHandler(CTRL1_5_Clicked);
        }

        public void CTRL1_5_Clicked(object sender,ClickedEventArgs e)
        {
            string projectTitle = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ID",this.NamespaceManager).Value; if (projectTitle == null || projectTitle == "")
            {
                projectTitle = "IncorrectIdentifier";
            }

            string currentDirect = Directory.GetCurrentDirectory();


            this.SaveAs(currentDirect + "/" + projectTitle + ".XML");

            //the line below also closes the application. If one need to just close the form,use this.Close() instead.
            //System.Environment.Exit(0);  

        }  
        
    }   
}

我找到了以下主题,这里有人说这是不可能的,但我不知道是否仍然如此: How to Publish InfoPath (which is fulltrusted having codebehid code ) in sharePoint?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...