Read and save data from C# app onto SharePoint

Thomas Lu 1 Reputation point
2022-05-09T10:04:28.383+00:00

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.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,882 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,858 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,146 Reputation points
    2022-05-10T08:44:03.83+00:00

    Hi @Thomas Lu ,

    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.


    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.