Load document from URL
Leave feedback
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;
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.