Hello,
What I am doing here is, first of all fetching the pages from sharepint and want to find and replace the content of that pages and save it back to the sharepoint site.
Example: I have created one page and in that page I have copied the link of google i.e. https://www.google.com. Now I have to update that text or link such that it will be https://www.microsoft.com. and this will be done using microsoft graph api.
Step 1: To fetch the Sharepoint Site Pages and I hvae fetched all the published pages succesfully.
Step 2: Now I have to find the text like https://www.ggogle.com and replace it with https://www.microsoft.com and save the updated page to the sharepoint site.
Anyone have any idea how can I achieve this?
Below is the sample code for fetching the pages from the Sharepoint:
Private Async Function GetSitePagesAsync(ByVal siteId As String, ByVal orderBy As Short, ByVal sortDescending As Boolean) As Task(Of List(Of SitePage))
If StringIsNullOrEmpty(siteId) Then Throw New ArgumentNullException("Site Id")
Dim objSitePages As New List(Of SitePage)
Dim objPageSitePages As SitePagesCollectionPage = Await _Client.Sites(siteId).Pages.Request().GetAsync
objSitePages = Await GetPagingData(objPageSitePages, objSitePages, Nothing)
If (Not objSitePages Is Nothing) AndAlso objSitePages.Count > 0 Then
'objSitePages.RemoveAll(Function(f) IsSitePage(f) = False)
Try
If orderBy = OptOrderBy.NAME Then
If sortDescending = True Then
objSitePages = objSitePages.OrderByDescending(Function(f) f.Name).ToList
Else
objSitePages = objSitePages.OrderBy(Function(f) f.Name).ToList
End If
End If
Catch ex As Exception
LogError(ex)
End Try
End If
Return objSitePages
End Function
Private Async Function GetPagingData(ByVal pobjSrc As Object, ByVal pobjDest As Object, ByVal pdtFromDate As Date?) As Task(Of Object)
If pobjSrc Is Nothing Then Return pobjDest
Dim blnSearchByDate As Boolean = False
Dim dtUtcFromDate As DateTimeOffset
If (TypeOf pobjSrc Is DriveItemChildrenCollectionPage) AndAlso (Not pdtFromDate Is Nothing) AndAlso (pdtFromDate.HasValue) Then
blnSearchByDate = True
dtUtcFromDate = pdtFromDate.Value.ToUniversalTime
End If
If blnSearchByDate Then
pobjDest.AddRange(DirectCast(pobjSrc, DriveItemChildrenCollectionPage).CurrentPage.Where(Function(f As DriveItem) If(Not f.File Is Nothing, f.LastModifiedDateTime.Value > dtUtcFromDate, (f.File Is Nothing))))
Else
pobjDest.AddRange(pobjSrc.CurrentPage)
End If
While (Not pobjSrc.NextPageRequest Is Nothing)
pobjSrc = Await pobjSrc.NextPageRequest.GetAsync
If blnSearchByDate Then
pobjDest.AddRange(DirectCast(pobjSrc, DriveItemChildrenCollectionPage).CurrentPage.Where(Function(f As DriveItem) If(Not f.File Is Nothing, f.LastModifiedDateTime.Value > dtUtcFromDate, (f.File Is Nothing))))
Else
pobjDest.AddRange(pobjSrc.CurrentPage)
End If
End While
Return pobjDest
End Function