Example #1
0
        private void ResolvePageHeaderImage()
        {
            try
            {
                this.siteId = this.clientContext.Site.EnsureProperty(p => p.Id);
                this.webId  = this.clientContext.Web.EnsureProperty(p => p.Id);

                if (!ImageServerRelativeUrl.StartsWith("/_LAYOUTS", StringComparison.OrdinalIgnoreCase))
                {
                    var pageHeaderImage = this.clientContext.Web.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(ImageServerRelativeUrl));
                    this.clientContext.Load(pageHeaderImage, p => p.UniqueId, p => p.ListId);
                    this.clientContext.ExecuteQueryRetry();

                    this.listId   = pageHeaderImage.ListId;
                    this.uniqueId = pageHeaderImage.UniqueId;
                }

                this.headerImageResolved = true;
            }
            catch (ServerException ex)
            {
                if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                {
                    // provided file link does not exist...we're eating the exception and the page will end up with a default page header
                    Log.Warning(Constants.LOGGING_SOURCE, CoreResources.ClientSidePageHeader_ImageNotFound, ImageServerRelativeUrl);
                }
                else if (ex.Message.Contains("SPWeb.ServerRelativeUrl"))
                {
                    // image resides in a different site collection context, we will simply allow it to be referred in the page header section.
                    Log.Warning(Constants.LOGGING_SOURCE, CoreResources.ClientSidePageHeader_ImageInDifferentWeb, imageServerRelativeUrl);
                    this.headerImageResolved = true;
                }
                else
                {
                    // the image can also refer to a path outside SharePoint, that is also allowed, so we will mark it as resolved and move ahead.
                    Log.Warning(Constants.LOGGING_SOURCE, CoreResources.ClientSidePageHeader_ImageInDifferentWeb, imageServerRelativeUrl);
                    this.headerImageResolved = true;
                    //throw;
                }
            }
        }
Example #2
0
        private async Task ResolvePageHeaderImageAsync()
        {
            try
            {
                await clientContext.Site.EnsurePropertiesAsync(p => p.Id).ConfigureAwait(false);

                await clientContext.Web.EnsurePropertiesAsync(p => p.Id).ConfigureAwait(false);

                siteId = clientContext.Site.Id;
                webId  = clientContext.Web.Id;

                if (!ImageServerRelativeUrl.StartsWith("/_LAYOUTS", StringComparison.OrdinalIgnoreCase))
                {
                    var pageHeaderImage = await clientContext.Web.GetFileByServerRelativeUrlAsync(ImageServerRelativeUrl, p => p.UniqueId, p => p.ListId).ConfigureAwait(false);

                    listId   = pageHeaderImage.ListId;
                    uniqueId = pageHeaderImage.UniqueId;
                }

                headerImageResolved = true;
            }
            catch (SharePointRestServiceException ex)
            {
                var error = ex.Error as SharePointRestError;

                if (File.ErrorIndicatesFileDoesNotExists(error))
                {
                    clientContext.Logger.LogInformation("Provided file link does not exist...we're eating the exception and the page will end up with a default page header");
                }
                else if (error.Message.Contains("SPWeb.ServerRelativeUrl"))
                {
                    headerImageResolved = true;
                    clientContext.Logger.LogInformation("Image resides in a different site collection context, we will simply allow it to be referred in the page header section");
                }
                else
                {
                    headerImageResolved = true;
                    clientContext.Logger.LogInformation("The image can also refer to a path outside SharePoint, that is also allowed, so we will mark it as resolved and move ahead");
                }
            }
        }
Example #3
0
        private void ResolvePageHeaderImage()
        {
            try
            {
                this.siteId = this.clientContext.Site.EnsureProperty(p => p.Id);
                this.webId  = this.clientContext.Web.EnsureProperty(p => p.Id);

                if (!ImageServerRelativeUrl.StartsWith("/_LAYOUTS", StringComparison.OrdinalIgnoreCase))
                {
                    var pageHeaderImage = this.clientContext.Web.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(ImageServerRelativeUrl));
                    this.clientContext.Load(pageHeaderImage, p => p.UniqueId, p => p.ListId);
                    this.clientContext.ExecuteQueryRetry();

                    this.listId   = pageHeaderImage.ListId;
                    this.uniqueId = pageHeaderImage.UniqueId;
                }

                this.headerImageResolved = true;
            }
            catch (ServerException ex)
            {
                if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                {
                    // provided file link does not exist...we're eating the exception and the page will end up with a default page header
                    Log.Warning(Constants.LOGGING_SOURCE, CoreResources.ClientSidePageHeader_ImageNotFound, ImageServerRelativeUrl);
                }
                else if (ex.Message.Contains("SPWeb.ServerRelativeUrl"))
                {
                    // image has to live in the web for which we've set up the client context...if not skip and log a warning
                    Log.Warning(Constants.LOGGING_SOURCE, CoreResources.ClientSidePageHeader_ImageInDifferentWeb, imageServerRelativeUrl);
                }
                else
                {
                    throw;
                }
            }
        }