Convert PDF attachment URL to memory stream format - C#

Ankaprasad
Posted by Ankaprasad under C# category on | Points: 40 | Views : 489
  /// <summary>
/// Convert attachment to memoryStream
/// </summary>
/// <param name="attachmentUrl"></param>
/// <returns></returns>
public static MemoryStream ConvertToStream(string attachmentUrl)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(attachmentUrl);
request.Headers.Add("Authorization", "{authentication code}");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
try
{
MemoryStream mem = new MemoryStream();
Stream stream = response.GetResponseStream();

stream.CopyTo(mem, 4096);
return mem;
}
finally
{
response.Close();
}
}

Comments or Responses

Login to post response