Skip to content

Instantly share code, notes, and snippets.

@KalinovDmitri
Created March 14, 2017 07:55
Show Gist options
  • Save KalinovDmitri/bf46bd4b1eed8e0cbbc9c4615e132e3a to your computer and use it in GitHub Desktop.
Save KalinovDmitri/bf46bd4b1eed8e0cbbc9c4615e132e3a to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CodeExamples.Tests
{
[TestClass]
public class FileWebRequestTests
{
#region Test methods
[TestMethod]
public void IsFileWebRequestsCreatesSuccessfully()
{
string desktopDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string sourcePath = @"\\some-network-path-to-your-file.txt";
string destinationPath = Path.Combine(desktopDirectory, Path.GetFileName(sourcePath));
WebRequest request = WebRequest.Create(sourcePath);
Assert.IsNotNull(request);
Assert.IsInstanceOfType(request, typeof(FileWebRequest));
Stream responseStream = request.GetResponse().GetResponseStream();
using (FileStream fileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.ReadWrite))
{
responseStream.CopyTo(fileStream);
fileStream.Flush(true);
}
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment