Click here to Skip to main content
15,867,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to set expiry date in excel file. I tried below code

public static void AddPermission()
        {
            Excel.Application ExcelApp = new Excel.Application();
            Workbook ExcelWorkBook = null;
            ExcelApp.Visible = true;
            ExcelWorkBook = ExcelApp.Workbooks.Open(@"C:\Workspace\OneModernize\April\Mywork\excelAccesssNet\TFSStatus.xlsx"); /// add excel path
            ExcelWorkBook.Activate();
            ExcelWorkBook.Permission.Enabled = true;
            DateTime dtExpireDate = DateTime.Now.AddDays(1);
            /// Add user mail xxx@cognizant.com
            ExcelWorkBook.Permission.Add("xxx@cognizant.com", MsoPermission.msoPermissionFullControl, ExpirationDate: dtExpireDate);
            ExcelWorkBook.Close();
            ExcelApp.Quit();
            Marshal.ReleaseComObject(ExcelWorkBook);
            Marshal.ReleaseComObject(ExcelApp);

                       

        }


What I have tried:

How to set expiry date in excel file
using c#
Posted
Comments
BillWoodruff 21-Apr-21 3:15am    
and what happened when you tried it ?
manuel_joseph 21-Apr-21 6:37am    
I got this error while run the application

Exception from HRESULT: 0x80041021
BillWoodruff 21-Apr-21 9:11am    
put breakpoints in your code and single-step through it until you isolate where the error occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900