Created
March 14, 2017 07:55
-
-
Save KalinovDmitri/bf46bd4b1eed8e0cbbc9c4615e132e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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