UpFileContent upfile = new UpFileContent();
upfile.StationImageName = "123.png";
FileStream fs = new FileStream(@"E:123.jpg", FileMode.Open, FileAccess.Read);
Byte[] btye2 = new byte[fs.Length];
fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
fs.Close();
upfile.ImageContent = btye2;
Stream sourceStream = new MemoryStream(upfile.ImageContent);
FileStream targetStream = null;
if (!sourceStream.CanRead)
{
throw new Exception("");
}
string DiskName = @"d:";
string FileAddress = @"ProductImagesSmall";
string LocationAddress = DiskName + FileAddress;
if (!Directory.Exists(LocationAddress))
{
Directory.CreateDirectory(LocationAddress);
}
string filePath = Path.Combine(LocationAddress, upfile.StationImageName);
using (targetStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
{
int count = 0;
const int bufferlength = 4096;
byte[] buffer = new byte[bufferlength];
while ((count = sourceStream.Read(buffer, 0, bufferlength)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
IsSuccess = true;
}