none
Download Images with RenditionID

    Question

  • Hello,

    I am able to download Images from SPO using code given below. My question is how to maintain the original size of the image which is mentioned in URL. (RenditionID=5 in my case)

    public static void DownoadFile(string FilePath,string DestinationPath)
            {
                //Filepath parameter to be passed below
                Uri filename = new Uri(@"https://mysiteurl.com/Sites/PublishingImages/2016/Test.jpg?RenditionID=6");
                string server = filename.AbsoluteUri.Replace(filename.AbsolutePath, "");
                string serverrelative = filename.AbsolutePath;
    
                ClientContext clientContext = new ClientContext("https://mysiteurl.com/Sites/");
                clientContext.Credentials = GetO365Credentials(ConfigurationManager.AppSettings["username"], ConfigurationManager.AppSettings["password"]);
                FileInformation f = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, serverrelative);
    
                //DestinationPath parameter to be used below
                using (var fileStream = new FileStream(@"c:\Test.jpg", FileMode.Create))
                    f.Stream.CopyTo(fileStream);
            }
    		
    		public static SharePointOnlineCredentials GetO365Credentials(string userName, string passWord)
            {
                SecureString securePassWord = new SecureString();
                foreach (char c in passWord.ToCharArray()) securePassWord.AppendChar(c);
                SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(userName, securePassWord);
                return credentials;
            }

    Thursday, December 1, 2016 10:30 AM

All replies