Setting Expiry Date to Infopath files - InfoPath Dev
in

InfoPath Dev

Setting Expiry Date to Infopath files

Last post 12-13-2007 09:09 PM by dhiru. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 12-13-2007 03:33 AM

    • dhiru
    • Not Ranked
      Male
    • Joined on 12-13-2007
    • Posts 2

    Setting Expiry Date to Infopath files

    Hi I want to set expiry date to info path files through C#.

    This is the code which I am using but its not working.Please tell me the problem.

    object docFilename = "D:\\Test\\2.xsn";

    object exp = MsoPermission.msoPermissionPrint;

    object blFalse = false;

    object blTrue = true;

    object objMissing = Type.Missing;

    Microsoft.Office.Interop.InfoPath.ApplicationClass oDoc;

    Microsoft.Office.Interop.InfoPath.ApplicationClass oWord = new Microsoft.Office.Interop.InfoPath.ApplicationClass();

    oDoc = oWord.XDocuments.Open(ref docFilename, ref objMissing, ref blFalse, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref blTrue, ref objMissing, ref objMissing, ref objMissing, ref objMissing);

    oDoc.Activate();

    oDoc.Permission.Enabled =
    true;

    oDoc.Permission.Add(username, exp, dtExpireDate);

    oDoc.Close(ref blTrue, ref objMissing, ref objMissing);oWord.Application.Quit(ref blTrue, ref objMissing, ref objMissing);

    oDoc = null;

    oWord = null;

     

    Filed under:
  • 12-13-2007 07:46 AM In reply to

    Re: Setting Expiry Date to Infopath files

    Give us a bit more details on what you are trying to accomplish.

    You want to no longer open new forms and to close itself immediately if it is past a certain age?  The xsn would only work with new forms, do you want existing forms (xml files) to be affected?

    I would think having a system process that would check a files date or age and then restrict access would be more effective.

  • 12-13-2007 09:09 PM In reply to

    • dhiru
    • Not Ranked
      Male
    • Joined on 12-13-2007
    • Posts 2

    Re: Setting Expiry Date to Infopath files

    Hi  Clay

      Thanks for your reply.

     actually I only want to set rights & expiry date to an existing files only.No new forms.

    for this I changed my code a little bit but its still giving some problem.The problem area is line

     oDoc1 = (_XDocument3)oWord.XDocuments.Open(infoFileName, (int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode); 

    Its throwing an exception here saying "{"InfoPath cannot open the following file: D:\\Test\\2.xsn.\nThe file is not a valid XML file.\n\nThe form contains XML that cannot be parsed:\nAn invalid character was found in text content.\r\n\nLine 1, Position 5\nMSCF\n----^\n"}"

     This same code is working fine for excel,word & powerpoint files.

    Please tell me where I am wrong.I am pasting my latest code here.

    object infoFileName = "D:\\Test\\2.xsn";

    Microsoft.Office.Interop.InfoPath._XDocument3 oDoc1;

    object exp = MsoPermission.msoPermissionPrint;

    Microsoft.Office.Interop.InfoPath.
    Application oWord = new Microsoft.Office.Interop.InfoPath.Application();

    oDoc1 = (_XDocument3)oWord.XDocuments.Open(infoFileName, (int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);

    oDoc1.Permission.Add( username, MsoPermission.msoPermissionRead, dtExpireDate);

    Filed under:
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.