Load document from URL

Following example demonstrates how to load document from URL.

 		public static void Run()
        {
            string url = "https://github.com/groupdocs-merger/GroupDocs.Merger-for-.NET/blob/master/Examples/Resources/SampleFiles/Pdf/example.pdf?raw=true";
            
            using (Stream stream = GetRemoteFile(url))
            {
                using (Merger merger = new Merger(stream))
                {
                    Console.WriteLine($"Document loaded from URL successfully.");
                }
            }
        }

        private static Stream GetRemoteFile(string url)
        {
            //ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
               | SecurityProtocolType.Tls11
               | SecurityProtocolType.Tls12
               | SecurityProtocolType.Ssl3;
            WebRequest request = WebRequest.Create(url);
            using (WebResponse response = request.GetResponse())
                return GetFileStream(response);
        }

        private static Stream GetFileStream(WebResponse response)
        {
            MemoryStream fileStream = new MemoryStream();
            using (Stream responseStream = response.GetResponseStream())
                responseStream.CopyTo(fileStream);
            fileStream.Position = 0;
            return fileStream;
        }

More resources

GitHub Examples 

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to merge your documents with our free online GroupDocs Merger App.