public async Task <string> GetDocument(string siteName, string docLibraryName, string id) { List <Option> options = new List <Option>(); options.Add(new QueryOption("search", siteName)); Site site = (await _graphServiceClient.Sites.Request(options).GetAsync()).First(); Drive docLibrary = (await(_graphServiceClient.Sites[site.Id].Drives.Request().GetAsync())).Where(x => x.Name == docLibraryName).First(); IEnumerable <DriveItem> documentsList = await _graphServiceClient.Sites[site.Id].Drives[docLibrary.Id].Root.Children.Request().GetAsync(); foreach (DriveItem document in documentsList) { Microsoft.Graph.ListItem item = await _graphServiceClient.Sites[site.Id].Drives[docLibrary.Id].Items[document.Id].ListItem.Request().GetAsync(); if (item.Id == id) { if ((document.File.MimeType.ToLower() == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") || (document.File.MimeType.ToLower() == "application / msword")) { using (Stream stream = await _graphServiceClient.Sites[site.Id].Drives[docLibrary.Id].Items[document.Id].Content.Request().GetAsync()) { WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(stream, false); Body body = wordprocessingDocument.MainDocumentPart.Document.Body; wordprocessingDocument.Close(); wordprocessingDocument.Dispose(); return(body.InnerText); } } if (document.File.MimeType.ToLower() == "application/pdf") { using (Stream stream = await _graphServiceClient.Sites[site.Id].Drives[docLibrary.Id].Items[document.Id].Content.Request().GetAsync()) { PdfReader _reader = new PdfReader(stream); ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(_reader, 1, strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); return(currentText); } } } } return("Lo siento, no he encontrado el documento que buscas."); }
public static async Task CreateActivities(Activities a) { var graphClient = GetAuthenticatedClient(); var fieldValueSet = new FieldValueSet(); fieldValueSet.AdditionalData = new Dictionary <string, object>(); fieldValueSet.AdditionalData.Add("Title", a.Title); fieldValueSet.AdditionalData.Add("Beskrivning", a.Beskrivning); fieldValueSet.AdditionalData.Add("Startdatum", a.Startdatum.ToString()); fieldValueSet.AdditionalData.Add("Slutdatum", a.Slutdatum.ToString()); fieldValueSet.AdditionalData.Add("Plats1", a.Plats); var listItem = new Microsoft.Graph.ListItem { Fields = fieldValueSet }; await graphClient.Sites[_siteId].Lists[_listId].Items .Request() .AddAsync(listItem); }
public static async Task Updateitem(string id) { using (var ctx = new ClientContext(_url)) { try { var pword = GetSecureString(_pword); ctx.Credentials = new SharePointOnlineCredentials(_uname, pword); var theList = ctx.Web.Lists.GetByTitle("Aktiviteter"); var theItem = theList.GetItemById(id); ctx.Load(theItem); ctx.ExecuteQuery(); var graphClient = GetAuthenticatedClient(); var me = await graphClient.Me .Request() .GetAsync(); UserCollection userCollection = ctx.Web.SiteUsers; ctx.Load(userCollection); ctx.ExecuteQuery(); List <FieldUserValue> listOfUserFields = new List <FieldUserValue>(); if (theItem["Deltagare"] != null) { foreach (FieldUserValue userFieldValue in theItem["Deltagare"] as FieldUserValue[]) { //if(userFieldValue) if (userFieldValue.Email != "") { listOfUserFields.Add(new FieldUserValue() { LookupId = userFieldValue.LookupId }); } } } FieldUserValue userValue = new FieldUserValue(); userValue.LookupId = userCollection.FirstOrDefault(x => x.UserPrincipalName == me.UserPrincipalName).Id; listOfUserFields.Add(userValue); theItem["Deltagare"] = listOfUserFields; theItem.Update(); theList.Update(); ctx.ExecuteQuery(); Microsoft.Graph.ListItem listItem = await GraphHelper.GetListItem(id); //Hårdkodade värden ska bytas ut mot dynamiska som kommer från vyn var @event = new Event { Subject = listItem.Fields.AdditionalData["Title"].ToString(), Body = new ItemBody { ContentType = BodyType.Html, Content = listItem.Fields.AdditionalData["Beskrivning"].ToString() }, Start = new DateTimeTimeZone { DateTime = listItem.Fields.AdditionalData["Startdatum"].ToString(), TimeZone = "Pacific Standard Time" }, End = new DateTimeTimeZone { DateTime = listItem.Fields.AdditionalData["Slutdatum"].ToString(), TimeZone = "Pacific Standard Time" }, Location = new Location { DisplayName = listItem.Fields.AdditionalData["Plats1"].ToString() } }; await CreateCalendarEvent(@event); } catch (Exception ex) { string msg = ex.Message; } } }