question

ThomasLu-2708 avatar image
0 Votes"
ThomasLu-2708 asked TongZhangMSFT-7548 commented

Read and save data from C# app onto SharePoint

For security reasons, our business is required to maintain a visitor control log to track when external guests enter and leave the premises.

When our infrastructure used to have on-prem file/storage servers, I had written a simple app that enabled the guests to check in and out via a public kiosk. When checking in, visitors' names, their internal contacts, and check-in times recorded in an Excel spreadsheet on a shared drive; upon checking out, the system would find them in the spreadsheet and append their check-out time. This was achieved using the DocumentFormat.OpenXml SDK.

We have since transitioned entirely to the cloud with SharePoint Online replacing our file servers, and I was trying to find some way to achieve something similar to the above without any success.

The options I found were the following:

  1. Map SharePoint Online site onto the local drive. Windows 10/11 KIOSK mode does not allow access to local drive.

  2. Save file to local drive and upload it. Windows 10/11 KIOSK mode does not allow access to local drive.

  3. Use Microsoft Graph A little stuck on how to find the ID of the file to be read from/written to.

Any pointers in the right direction, particularly with Microsoft Graph and identifying the file I intend to use, would be much appreciated.



dotnet-csharpoffice-sharepoint-onlinemicrosoft-graph-explorer
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ThomasLu-2708,

I am currently doing some research on this issue, will let you know as soon as possible.

0 Votes 0 ·

1 Answer

TongZhangMSFT-7548 avatar image
1 Vote"
TongZhangMSFT-7548 answered TongZhangMSFT-7548 commented

Hi @ThomasLu-2708,

Per my research and testing, you can use the follow graph api to find ID of the file in the list:

 GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{itemid}

200579-screenshot-2022-05-10-162113.png

By the way, do you want to display the check-in/check-out information directly in a SharePoint list, or do you still store the information in excel and then upload the excel to SharePoint?

I did a test using CSOM, in my test, to determine if the user exists in the list, if not, add the user and the check-in time to that list, if it exists, then add the check-out time. Here is my test code. Hope it can help you :

        static void Main(string[] args)
         {
             var clientContext = GetonlineContext();
             Web web = clientContext.Web;
             List targetList = clientContext.Web.Lists.GetByTitle("ListTest");
             CamlQuery oQuery = new CamlQuery();
             oQuery.ViewXml = @"<View><Query><Where>
                                 <Eq>
                                 <FieldRef Name='name' />
                                 <Value Type='Text'>zella</Value>
                                 </Eq>
                                 </Where></Query></View>";
    
             ListItemCollection oItems = targetList.GetItems(oQuery);
             clientContext.Load(oItems);
             clientContext.ExecuteQuery();
             ListItem oItem = oItems.FirstOrDefault();
             if(oItem !=null)
             {
                 oItem["check_x002d_outtimes"] = DateTime.UtcNow;
                 oItem.Update();
                 clientContext.ExecuteQuery();
             }
             else
             {
                 ListItemCreationInformation oListItemCreationInformation = new ListItemCreationInformation();
                 ListItem oItemadd = targetList.AddItem(oListItemCreationInformation);
                 oItemadd["name"] = "zella";
                 oItemadd["check_x002d_intimes"] = DateTime.UtcNow;
                 oItemadd.Update();
                 clientContext.ExecuteQuery();
             }
         }

if not exists : 200538-image.png
if exists: 200539-image.png


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.






image.png (7.3 KiB)
image.png (7.3 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ThomasLu-2708,

I am checking to see if the problem has been resolved. If you have any questions or progress, you can contact me in time.

0 Votes 0 ·