Showing posts with label MS Office. Show all posts
Showing posts with label MS Office. Show all posts

Tuesday, March 12, 2024

Get Graph Id of folder or file in SharePoint Online UI without code

Often when we work with SharePoint Online via its APIs we will encouter situations to know the Graph id of documents or folders. Mainly when we want to debug our automation code or any code written aginst Graph API. The Graph Id is currently not displayed anywhere in the UI. This video shows how can we get the Graph Id of a document from UI or without writing code.

Urls used in the video

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFolderByServerRelativeUrl('/sites/DataSite/Important%20Files/')

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFileByServerRelativeUrl('/sites/DataSite/Important%20Files/Project01/tracker.xlsx')/ListItemAllFields

https://vermarajneesh.sharepoint.com/sites/DataSite/_api/web/GetFileByServerRelativeUrl('/sites/DataSite/Important%20Files/Project01/tracker.xlsx')/ListItemAllFields/File?$select=VroomItemId

References

VroomId added - https://devblogs.microsoft.com/microsoft365dev/new-sharepoint-csom-version-released-for-sharepoint-online-august-2020/

Tuesday, June 13, 2023

Understanding the throttling in SharePoint Online

As mentioned many times in this blog, it is very easy to use SharePoint for document management and to maintain a small list without writing a custom application. But it is a nightmare when it comes to customizing SharePoint and interacting with it from other applications from APIs. One of the challenges is the throttling behavior. 

We should agree that it is a SaaS application and Microsoft cannot fulfill all our API requests. They should throttle for the below reasons

  • In order to manage noisy neighbors give equal consideration to all the tenant
  • Ensure the availability of the entire system
The problem is the throttling details are not clear from the documentation. None available if we ended up in a situation where we need to use user-based flow. Forget about using ROPC flow from a daemon application. 
Below is a flow chart that is trying to make sense of when our application will get throttled by Microsoft.
Click on it to open as SVG to navigate to the links.

Tuesday, April 7, 2020

Contributing to one more open source GitHub project - tfstasksinoutlook

Background

When we are working from the office, we talk to people, show them what we did, help them solve their problem, etc,. That makes sure everybody knows that we are doing. Even if we are not religiously following the project management tools such as TFS. Even though there are no tasks planned in TFS for us in advance, people know we will be working on something. 
But that is different when we work from home. As of writing this post, the entire IT world working from home due to COVID-19. Instead of people asking us, are you free to do something? they may directly go to TFS and see what is our plan. If the TFS is not inline, we may get unplanned works and our planned works will be in trouble. 

If we are working as pure developers taking work items from TFS every morning, life is easy. We know or at least easy to plan what to be done. But it is different when we are up on the ladder. A lot of unplanned meetings may come into out way than actual technical works. Those will be in the outlook or a different planning tool than where our code and work items reside. If we don't get the full view of meetings and work, it is difficult to plan and making sure we show our status correctly.

Problem

In order to get the full view of the meetings and work items, we need to consolidate all in one place. One way is to create work items for each and every meeting and set the Start and Finish date and times respectively. There could be scenarios where clients move the meetings or cancel those. Need to sync up again

Another problem is that TFS doesn't have a calendar view to realize how we spend our day. Many companies don't care about each hour how we spend. But some need to know at the accuracy of 30 mins.
There is a team calendar plugin for Azure Dev Ops. But it may not be applicable in our company which is still with the on-premise TFS server. Not on-premise Azure DevOps Server Also, the team calendar is not designed to solve the problems we are dealing with there.

Approaches

Custom application

Develop a custom application to bring outlook calendar and TFS items and show those using a calendar control. Additional functionalities to create tasks and meetings can be added. This is a long route including hosting, authentication, etc...

Buy a product

There are some commercial outlook add-ins that merge TFS items into outlook calendar. But this category involves money which inturn involves approvals and all. All the features may not be there readily so we may need to spend time with the vendor to include the features we need also the options to customize. But it separates our problem of timekeeping to somewhere else and helps us to concentrate on our core business. People who can go this path should go here. 

Open-source / free Outlook add-in to bring TFS items

One last option is to search for any free or open-source outlook add-in. Free tools may not be having all the features we need. If there are just go for it. Open-source helps us to issue a pull request if we don't see the feature and would like to add one. 
Again there is no guarantee that all open-source projects in GitHub or anywhere else accept our PRs. Sometimes it may be more time consuming than buying a product or getting a feature into a free tool..

Solution

This may not be the solution for all. But at least it is working for me. I did some research in GitHub and figured out one Outlook add-in project named tfstasksinoutlook. I tried to use it and could see it is stable and has the basic features I need. The main attraction was it run, fetched TFS items and added to outlook calendar in the first attempt itself.

It is not that much documented. But easily figured out the process of what they are following. It is simple as creating an issue and issue a PR. Obvious in GitHub. Isn't it?

Tried the same path. It was staying idle for long time with the tools and technology versions of that time. I just upgraded the project to VS 2019 and the framework to 4.6 and issued a PR. To my surprise, it got approved within 1 day.

It needs some more features such as showing the start and finish dates, aligning the meeting based on the start and finish date of the work item, adding the TFS task from calendar items, etc...

PR to show "start and finish dates" is already given and got approved. Hopefully can give next PR to align the calendar item to start and finish date soon.

Benefits of open-source

Readers may stop here and just read the last line as they might have heard the benefits of open source. Below are some benefits I got by participating in this project.
  • Refreshed WPF skills. (Good as everybody forecasting a recession :))
  • Learned a different design for WPF applications. This project uses the System.Reactive than traditional MVVm.
  • Reading other's code and improving my coding skills.
  • Of course, a tool to view my TFS items and meetings in one place.
I believe the project got below benefits from my contributions
  • More issues logged
  • Little active after years with some features.
  • Upgraded tools and frameworks to a better shape. Not to the greatest, it is still .Net 4.6
  • A unit test project. Hopefully, people come after me will write unit tests
Thanks very much, Sergii for your nice open-sourced work.

Tuesday, July 30, 2013

Office Interop - ComExcetion HRESULT: 0x800A03EC when large text values in formulas

Office Interop in .Net

Office interop cannot be avoided, if you are developing applications for Windows platform. It is 90% sure that your customers will ask for MS Office integration when the project grows or your marketing people will add office integration regardless the client actually needs or not.

Before Open XML era (docx,xlsx etc...) developers had only one way to interact with office files from .Net or any other applications. Yes the Office interop APIs. In .Net it can be done by Adding reference to the interop assemblies.Only issue I had faced is the non type safe APIs provided. Another issue is the memory leak due to unmanaged objects but that can be avoided by using Marshal.ReleaseComObject method.

If you are working in .Net for 2 years and don't know what is Office interop and how to use it to create an Excel file programatically, just google for it and try at least once. Let me know, if you are not able to get any result in google

Adding formula to Excel cells from C#.Net

Formula in Excel should be known to everyone who uses Windows operating system seriously. It can be added from the Excel application by prefixing a '=' symbol to mathematical or logical expressions when we edit cells. For example if you want to display the sum of values in cells E1 to E9 in E10 cell, write the below into E10 cell

=SUM(E1:E9)

The same can be done from our .Net application as well. Below is an code which adds little more complicated formulae to the cell


Application app = new Application();
Workbook wb= app.Workbooks.Open(excelFilePath);
Worksheet firstSheet = wb.Sheets[1] as  Worksheet;
string message = "There is a 'No' in the range B1-B10";
string formula = @"=IF(COUNTIF(B1:B10,""No"") >0,"""+message+@""","""")";
firstSheet.Cells[1, 1]= formula;//This is cell A1
wb.Save();
wb.Close();
Marshal.ReleaseComObject(app);


This means

  1. It will create an excel file in the path mentioned in the variable excelFilePath
  2. It will add a formula in the cell A1.
  3. The formula will be '=IF(COUNTIF(B1:B10,"No") > 0,"There is a No in the range B1-B10","")
  4. The formula means, if any cell in the range B1 to B10 contains "No" string it will show the message "There is a No in the range B1-B10" in the cell A1
This is simple right. But what about the below ie I want to set a big text to the A1 cell when there is a "No" in the range.

      

Application app = new Application();
Workbook wb= app.Workbooks.Open(excelFilePath);
Worksheet firstSheet = wb.Sheets[1] as  Worksheet;
 
string message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur";

string formula = @"=IF(COUNTIF(B1:B10,""No"") >0,"""+message+@""","""")";
firstSheet.Cells[1, 1]= formula;
wb.Save();
wb.Close();
Marshal.ReleaseComObject(app);

This simply fails with a message

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC

Any idea? It doesn't talk about what happened inside the code.Or at least what is the actual error?

This is the time to show the your practical debugging skills. Most of the developers complain here that, its just not working. But the intelligent developers think in a different way. Is it because of long message? Can't I assign long text via interop? or Excel itself just don't accept this much big message?

Most of them ends up in trying out the same scenario in Excel. Technically this is called as "reproducing the issue in a stripped down environment". Whoever try it in Excel will get the actual problem.

Text values in formulas are limited to 255 characters. To create text values longer than 255 characters in a formula, use the CONCATENATE function or the concatenation operator (&)

Yes there is a limitation in Excel and it itself giving the solution. So lets modify our code to have concatenation.

Application app = new Application();
Workbook wb = app.Workbooks.Open(excelFilePath);
Worksheet firstSheet = wb.Sheets[1] as Worksheet;

string message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ";
message+=@"""&"""+"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur";
string formula = @"=IF(COUNTIF(B1:B10,""No"") >0,""" + message + @""","""")";
firstSheet.Cells[1, 1] = formula;
wb.Save();
wb.Close();
Marshal.ReleaseComObject(app);

Looks good. But in real scenario things will not be easy like this. Your application may be getting the message from some other sources which requires a splitting on the fly.

Happy debugging.

Monday, July 22, 2013

DSOFile in 64bit to deal with Office 2013 custom properties

DSOFile.dll is the way to edit Microsoft office document properties without the office installed. Microsoft claims that it is independent, but I had came across scenarios where it requires one more file installed in the machine which is msoshext.dll at the location.

C:\Program Files\Common Files\Microsoft Shared\OFFICE<version>\msoshext.dll
eg: C:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\msoshext.dll

This post is about an issue which you may face, if you run your application which uses DSOFile.dll in 64 bit machines with 32bit Office 2013 installed. Mainly when you run 32 bit apps in 64 bit.The issue occurs when ever the supporting file msoshext.dll is not present for target version of the applications which uses the DSOFile.dll. Lets see the scenario in deep.

The below code snippet is something which adds a custom property to the word document. If you are not familiar about the custom properties in office document just open a word file in MS word, go to properties page and select the custom tab.


                OleDocumentPropertiesClass doc = new OleDocumentPropertiesClass();
                doc.Open("test.docx", false, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
                object val = "joysvalue";
                doc.CustomProperties.Add("joyskey", ref val);
                doc.Save();


You may experience as it just stopped updating the custom properties in the above environment (64Bit machines which have 32bit office). ie if you look at the custom properties dialog after opening the docx file you cannot see it there.

But interesting thing is, if you again try to add the same custom property you will get an exception. I tried as much as I can to identify where the custom property is being stored but I can't find out. We can verify it as well by executing the below code


                OleDocumentPropertiesClass oleDocument = new OleDocumentPropertiesClass();
                oleDocument.Open("test.docx", false, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
                foreach (CustomProperty property in oleDocument.CustomProperties)
                {
                    Console.WriteLine("Pro Name {0},Value{1}", property.Name, property.get_Value());
                }


Simply saying, the first code snippet added the custom property to the document. Its accessible, if we iterate the CustomProperties collection but cannot visible in the office application's custom properties page.

Alternative

When you put this question in developer forums you will get an advise to go with open xml sdk. This is the solution to the problem but the drawback is it will work only with the open xml office documents such as docx,pptx,xlsx etc...The old office documents such as .doc, .ppt, .xls etc... are not at all supported by open xml sdk.So if your application needs to deal with both the formats using same code base you need to find the solution to the DSOFile issues in 64 bit. 

Solution

Install all the latest possible office 2013 updates and make sure you have the msoshext.dll in the right location. If your application is 32 bit you need to have the file in the c:\program files (x86)\ folder. Also make sure that the DSOFile.dll is registered properly for 32 bit (Using C:\Windows\SysWOW64\regsvr32.exe) and 64 bit in the 64 bit environment.

The above updating is applicable to all versions of office, if its installed in 64 bit machines.