Dear All,
We are trying set Expiry Date to file objects and getting the error "Value does not fall within the expected range"

Please check the code below and guide

--------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Core;
using ExcelInterop = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;


class Program
{
private void ImposeExpiryDate()
{

//For Excel
ExcelInterop.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass ();

ExcelInterop.WorkbookClass workBook = (ExcelInterop.WorkbookClass)excel.Workbooks.Open( "c:\\test.xls", 0, true, 5, "" , "", true, ExcelInterop. XlPlatform .xlWindows, "\t", false, false , 0, true, 1, 0);
ExcelInterop.Sheets sheets = workBook.Worksheets;

DateTime dtExpirationDate = DateTime.Today.AddDays(2);
try
{
workBook.Permission.Add(@"[email protected]" ,Microsoft.Office.Core.MsoPermission.msoPermissionFullControl, dtExpirationDate);
}

catch (Exception EX)
{
// "Value does not fall within the expected range" ???
}


//For Word
// Microsoft.Office.Interop.Word.ApplicationClass WordApp =
// new Microsoft.Office.Interop.Word. ApplicationClass ();
// Microsoft.Office.Interop.Word.Document aDoc =
// WordApp.Documents.Open(ref fileName, ref missing,
// ref readOnly, ref missing, ref missing, ref missing,
// ref missing, ref missing, ref missing, ref missing,
// ref missing, ref isVisible);

// aDoc.Permission.Add
// ("[email protected]" ,
// Microsoft.Office.Core.MsoPermission.msoPermissionFullControl,
// dtExpirationDate);
}

}




Regards
Sachin