No Description

ImageUpload.cs 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using System.Web.UI.HtmlControls;
  5. using System.Drawing;
  6. using System.Net;
  7. namespace CallCenter.Utility
  8. {
  9. /// <summary>
  10. /// 文件类型
  11. /// </summary>
  12. public enum FileExtension
  13. {
  14. JPG = 255216,
  15. GIF = 7173,
  16. BMP = 6677,
  17. PNG = 13780,
  18. RAR = 8297,
  19. jpg = 255216,
  20. exe = 7790,
  21. xml = 6063,
  22. html = 6033,
  23. aspx = 239187,
  24. cs = 117115,
  25. js = 119105,
  26. txt = 210187,
  27. sql = 255254
  28. }
  29. /// <summary>
  30. /// 图片检测类
  31. /// </summary>
  32. public static class FileValidation
  33. {
  34. #region 上传图片检测类
  35. /// <summary>
  36. /// 是否允许
  37. /// </summary>
  38. public static bool IsAllowedExtension(HttpPostedFile oFile, FileExtension[] fileEx)
  39. {
  40. int fileLen = oFile.ContentLength;
  41. byte[] imgArray = new byte[fileLen];
  42. oFile.InputStream.Read(imgArray, 0, fileLen);
  43. MemoryStream ms = new MemoryStream(imgArray);
  44. System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
  45. string fileclass = "";
  46. byte buffer;
  47. try
  48. {
  49. buffer = br.ReadByte();
  50. fileclass = buffer.ToString();
  51. buffer = br.ReadByte();
  52. fileclass += buffer.ToString();
  53. }
  54. catch { }
  55. br.Close();
  56. ms.Close();
  57. foreach (FileExtension fe in fileEx)
  58. {
  59. if (Int32.Parse(fileclass) == (int)fe) return true;
  60. }
  61. return false;
  62. }
  63. /// <summary>
  64. /// 上传前的图片是否可靠
  65. /// </summary>
  66. public static bool IsSecureUploadPhoto(HttpPostedFile oFile)
  67. {
  68. bool isPhoto = false;
  69. string fileExtension = System.IO.Path.GetExtension(oFile.FileName).ToLower();
  70. string[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
  71. for (int i = 0; i < allowedExtensions.Length; i++)
  72. {
  73. if (fileExtension == allowedExtensions[i])
  74. {
  75. isPhoto = true;
  76. break;
  77. }
  78. }
  79. if (!isPhoto)
  80. {
  81. return true;
  82. }
  83. FileExtension[] fe = { FileExtension.BMP, FileExtension.GIF, FileExtension.JPG, FileExtension.PNG };
  84. if (IsAllowedExtension(oFile, fe))
  85. return true;
  86. else
  87. return false;
  88. }
  89. /// <summary>
  90. /// 上传后的图片是否安全
  91. /// </summary>
  92. /// <param name="photoFile">物理地址</param>
  93. public static bool IsSecureUpfilePhoto(string photoFile)
  94. {
  95. bool isPhoto = false;
  96. string Img = "Yes";
  97. string fileExtension = System.IO.Path.GetExtension(photoFile).ToLower();
  98. string[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
  99. for (int i = 0; i < allowedExtensions.Length; i++)
  100. {
  101. if (fileExtension == allowedExtensions[i])
  102. {
  103. isPhoto = true;
  104. break;
  105. }
  106. }
  107. if (!isPhoto)
  108. {
  109. return true;
  110. }
  111. StreamReader sr = new StreamReader(photoFile, System.Text.Encoding.Default);
  112. string strContent = sr.ReadToEnd();
  113. sr.Close();
  114. string str = "request|<script|.getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=";
  115. foreach (string s in str.Split('|'))
  116. {
  117. if (strContent.ToLower().IndexOf(s) != -1)
  118. {
  119. File.Delete(photoFile);
  120. Img = "No";
  121. break;
  122. }
  123. }
  124. return (Img == "Yes");
  125. }
  126. #endregion
  127. }
  128. /// <summary>
  129. /// 图片上传类
  130. /// </summary>
  131. //----------------调用-------------------
  132. //imageUpload iu = new imageUpload();
  133. //iu.AddText = "";
  134. //iu.CopyIamgePath = "";
  135. //iu.DrawString_x = ;
  136. //iu.DrawString_y = ;
  137. //iu.DrawStyle = ;
  138. //iu.Font = "";
  139. //iu.FontSize = ;
  140. //iu.FormFile = File1;
  141. //iu.IsCreateImg =;
  142. //iu.IsDraw = ;
  143. //iu.OutFileName = "";
  144. //iu.OutThumbFileName = "";
  145. //iu.SavePath = @"~/image/";
  146. //iu.SaveType = ;
  147. //iu.sHeight = ;
  148. //iu.sWidth = ;
  149. //iu.Upload();
  150. //--------------------------------------
  151. public class ImageUpload
  152. {
  153. #region 私有成员
  154. private int _Error = 0;//返回上传状态。
  155. private int _MaxSize = 10 * 1024 * 1024;//最大单个上传文件 (默认)
  156. private string _FileType = "jpg;gif;bmp;png";//所支持的上传类型用"/"隔开
  157. private string _SavePath = System.Web.HttpContext.Current.Server.MapPath(".") + "\\";//保存文件的实际路径
  158. private int _SaveType = 0;//上传文件的类型,0代表自动生成文件名
  159. private HtmlInputFile _FormFile;//上传控件。
  160. private string _DataUrl;//base64编码的文本
  161. private string _InFileName = "";//非自动生成文件名设置。
  162. private string _OutFileName = "";//输出文件名。
  163. private bool _IsCreateImg = true;//是否生成缩略图。
  164. private bool _Iss = false;//是否有缩略图生成.
  165. private int _Height = 0;//获取上传图片的高度
  166. private int _Width = 0;//获取上传图片的宽度
  167. private int _sHeight = 120;//设置生成缩略图的高度
  168. private int _sWidth = 120;//设置生成缩略图的宽度
  169. private bool _IsDraw = false;//设置是否加水印
  170. private int _DrawStyle = 0;//设置加水印的方式0:文字水印模式,1:图片水印模式,2:不加
  171. private int _DrawString_x = 10;//绘制文本的X坐标(左上角)
  172. private int _DrawString_y = 10;//绘制文本的Y坐标(左上角)
  173. private string _AddText = "GlobalNatureCrafts";//设置水印内容
  174. private string _Font = "宋体";//设置水印字体
  175. private int _FontSize = 12;//设置水印字大小
  176. private int _FileSize = 0;//获取已经上传文件的大小
  177. private string _CopyIamgePath = System.Web.HttpContext.Current.Server.MapPath(".") + "/images/5dm_new.jpg";//图片水印模式下的覆盖图片的实际地址
  178. #endregion
  179. #region 公有属性
  180. /// <summary>
  181. /// Error返回值
  182. /// 1、没有上传的文件
  183. /// 2、类型不允许
  184. /// 3、大小超限
  185. /// 4、未知错误
  186. /// 0、上传成功。
  187. /// </summary>
  188. public int Error
  189. {
  190. get { return _Error; }
  191. }
  192. /// <summary>
  193. /// 最大单个上传文件
  194. /// </summary>
  195. public int MaxSize
  196. {
  197. set { _MaxSize = value; }
  198. }
  199. /// <summary>
  200. /// 所支持的上传类型用";"隔开
  201. /// </summary>
  202. public string FileType
  203. {
  204. set { _FileType = value; }
  205. }
  206. /// <summary>
  207. /// 保存文件的实际路径
  208. /// </summary>
  209. public string SavePath
  210. {
  211. set { _SavePath = System.Web.HttpContext.Current.Server.MapPath(value); }
  212. get { return _SavePath; }
  213. }
  214. /// <summary>
  215. /// 上传文件的类型,0代表自动生成文件名
  216. /// </summary>
  217. public int SaveType
  218. {
  219. set { _SaveType = value; }
  220. }
  221. /// <summary>
  222. /// 上传控件
  223. /// </summary>
  224. public HtmlInputFile FormFile
  225. {
  226. set { _FormFile = value; }
  227. }
  228. /// <summary>
  229. /// base64编码的文本
  230. /// </summary>
  231. public string DataUrl
  232. {
  233. set { _DataUrl = value; }
  234. }
  235. /// <summary>
  236. /// 非自动生成文件名设置。
  237. /// </summary>
  238. public string InFileName
  239. {
  240. set { _InFileName = value; }
  241. }
  242. /// <summary>
  243. /// 输出文件名
  244. /// </summary>
  245. public string OutFileName
  246. {
  247. get { return _OutFileName; }
  248. set { _OutFileName = value; }
  249. }
  250. /// <summary>
  251. /// 输出的缩略图文件名
  252. /// </summary>
  253. public string OutThumbFileName
  254. {
  255. get;
  256. set;
  257. }
  258. /// <summary>
  259. /// 是否有缩略图生成.
  260. /// </summary>
  261. public bool Iss
  262. {
  263. get { return _Iss; }
  264. }
  265. /// <summary>
  266. /// 获取上传图片的宽度
  267. /// </summary>
  268. public int Width
  269. {
  270. get { return _Width; }
  271. }
  272. /// <summary>
  273. /// 获取上传图片的高度
  274. /// </summary>
  275. public int Height
  276. {
  277. get { return _Height; }
  278. }
  279. /// <summary>
  280. /// 设置缩略图的宽度
  281. /// </summary>
  282. public int sWidth
  283. {
  284. get { return _sWidth; }
  285. set { _sWidth = value; }
  286. }
  287. /// <summary>
  288. /// 设置缩略图的高度
  289. /// </summary>
  290. public int sHeight
  291. {
  292. get { return _sHeight; }
  293. set { _sHeight = value; }
  294. }
  295. /// <summary>
  296. /// 是否生成缩略图
  297. /// </summary>
  298. public bool IsCreateImg
  299. {
  300. get { return _IsCreateImg; }
  301. set { _IsCreateImg = value; }
  302. }
  303. /// <summary>
  304. /// 是否加水印
  305. /// </summary>
  306. public bool IsDraw
  307. {
  308. get { return _IsDraw; }
  309. set { _IsDraw = value; }
  310. }
  311. /// <summary>
  312. /// 设置加水印的方式
  313. /// 0:文字水印模式
  314. /// 1:图片水印模式
  315. /// 2:不加
  316. /// </summary>
  317. public int DrawStyle
  318. {
  319. get { return _DrawStyle; }
  320. set { _DrawStyle = value; }
  321. }
  322. /// <summary>
  323. /// 绘制文本的X坐标(左上角)
  324. /// </summary>
  325. public int DrawString_x
  326. {
  327. get { return _DrawString_x; }
  328. set { _DrawString_x = value; }
  329. }
  330. /// <summary>
  331. /// 绘制文本的Y坐标(左上角)
  332. /// </summary>
  333. public int DrawString_y
  334. {
  335. get { return _DrawString_y; }
  336. set { _DrawString_y = value; }
  337. }
  338. /// <summary>
  339. /// 设置文字水印内容
  340. /// </summary>
  341. public string AddText
  342. {
  343. get { return _AddText; }
  344. set { _AddText = value; }
  345. }
  346. /// <summary>
  347. /// 设置文字水印字体
  348. /// </summary>
  349. public string Font
  350. {
  351. get { return _Font; }
  352. set { _Font = value; }
  353. }
  354. /// <summary>
  355. /// 设置文字水印字的大小
  356. /// </summary>
  357. public int FontSize
  358. {
  359. get { return _FontSize; }
  360. set { _FontSize = value; }
  361. }
  362. /// <summary>
  363. /// 文件大小
  364. /// </summary>
  365. public int FileSize
  366. {
  367. get { return _FileSize; }
  368. set { _FileSize = value; }
  369. }
  370. /// <summary>
  371. /// 图片水印模式下的覆盖图片的实际地址
  372. /// </summary>
  373. public string CopyIamgePath
  374. {
  375. set { _CopyIamgePath = System.Web.HttpContext.Current.Server.MapPath(value); }
  376. }
  377. public HttpPostedFile PostFile { get; set; }
  378. #endregion
  379. #region 私有方法
  380. /// <summary>
  381. /// 获取文件的后缀名
  382. /// </summary>
  383. private string GetExt(string path)
  384. {
  385. return Path.GetExtension(path);
  386. }
  387. /// <summary>
  388. /// 获取输出文件的文件名
  389. /// </summary>
  390. private string FileName(string Ext)
  391. {
  392. if (_SaveType == 0 || _InFileName.Trim() == "")
  393. return "(" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ")" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + Ext;
  394. else
  395. return "(" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ")" + _InFileName;
  396. }
  397. /// <summary>
  398. /// 检查上传的文件的类型,是否允许上传。
  399. /// </summary>
  400. private bool IsUpload(string Ext)
  401. {
  402. Ext = Ext.Replace(".", "");
  403. bool b = false;
  404. string[] arrFileType = _FileType.Split(';');
  405. foreach (string str in arrFileType)
  406. {
  407. if (str.ToLower() == Ext.ToLower())
  408. {
  409. b = true;
  410. break;
  411. }
  412. }
  413. return b;
  414. }
  415. #endregion
  416. #region 上传图片
  417. public void Upload()
  418. {
  419. HttpPostedFile hpFile = PostFile;
  420. if (hpFile == null || hpFile.FileName.Trim() == "")
  421. {
  422. _Error = 1;
  423. return;
  424. }
  425. string Ext = GetExt(hpFile.FileName);
  426. if (!IsUpload(Ext))
  427. {
  428. _Error = 2;
  429. return;
  430. }
  431. int iLen = hpFile.ContentLength;
  432. if (iLen > _MaxSize)
  433. {
  434. _Error = 3;
  435. return;
  436. }
  437. try
  438. {
  439. if (!Directory.Exists(_SavePath)) Directory.CreateDirectory(_SavePath);
  440. byte[] bData = new byte[iLen];
  441. hpFile.InputStream.Read(bData, 0, iLen);
  442. string FName;
  443. FName = FileName(Ext);
  444. string TempFile = "";
  445. if (_IsDraw)
  446. {
  447. TempFile = FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString();
  448. }
  449. else
  450. {
  451. TempFile = FName;
  452. }
  453. FileStream newFile = new FileStream(_SavePath + TempFile, FileMode.Create);
  454. newFile.Write(bData, 0, bData.Length);
  455. newFile.Flush();
  456. int _FileSizeTemp = hpFile.ContentLength;
  457. string ImageFilePath = _SavePath + FName;
  458. if (_IsDraw)
  459. {
  460. if (_DrawStyle == 0)
  461. {
  462. System.Drawing.Image Img1 = System.Drawing.Image.FromStream(newFile);
  463. Graphics g = Graphics.FromImage(Img1);
  464. g.DrawImage(Img1, 100, 100, Img1.Width, Img1.Height);
  465. Font f = new Font(_Font, _FontSize);
  466. Brush b = new SolidBrush(Color.Red);
  467. string addtext = _AddText;
  468. g.DrawString(addtext, f, b, _DrawString_x, _DrawString_y);
  469. g.Dispose();
  470. Img1.Save(ImageFilePath);
  471. Img1.Dispose();
  472. }
  473. else
  474. {
  475. System.Drawing.Image image = System.Drawing.Image.FromStream(newFile);
  476. System.Drawing.Image copyImage = System.Drawing.Image.FromFile(_CopyIamgePath);
  477. Graphics g = Graphics.FromImage(image);
  478. g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width - 5, image.Height - copyImage.Height - 5, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
  479. g.Dispose();
  480. image.Save(ImageFilePath);
  481. image.Dispose();
  482. }
  483. }
  484. //获取图片的高度和宽度
  485. System.Drawing.Image Img = System.Drawing.Image.FromStream(newFile);
  486. _Width = Img.Width;
  487. _Height = Img.Height;
  488. //生成缩略图部分
  489. if (_IsCreateImg)
  490. {
  491. #region 缩略图大小只设置了最大范围,并不是实际大小
  492. float realbili = (float)_Width / (float)_Height;
  493. float wishbili = (float)_sWidth / (float)_sHeight;
  494. //实际图比缩略图最大尺寸更宽矮,以宽为准
  495. if (realbili > wishbili)
  496. {
  497. _sHeight = (int)((float)_sWidth / realbili);
  498. }
  499. //实际图比缩略图最大尺寸更高长,以高为准
  500. else
  501. {
  502. _sWidth = (int)((float)_sHeight * realbili);
  503. }
  504. #endregion
  505. this.OutThumbFileName = FName.Split('.').GetValue(0).ToString() + "_s." + FName.Split('.').GetValue(1).ToString();
  506. string ImgFilePath = _SavePath + this.OutThumbFileName;
  507. System.Drawing.Image newImg = Img.GetThumbnailImage(_sWidth, _sHeight, null, System.IntPtr.Zero);
  508. newImg.Save(ImgFilePath);
  509. newImg.Dispose();
  510. _Iss = true;
  511. }
  512. if (_IsDraw)
  513. {
  514. if (File.Exists(_SavePath + FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString()))
  515. {
  516. newFile.Dispose();
  517. File.Delete(_SavePath + FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString());
  518. }
  519. }
  520. newFile.Close();
  521. newFile.Dispose();
  522. _OutFileName = FName;
  523. _FileSize = _FileSizeTemp;
  524. _Error = 0;
  525. return;
  526. }
  527. catch
  528. {
  529. _Error = 4;
  530. return;
  531. }
  532. }
  533. public void Upload64()
  534. {
  535. int delLength = _DataUrl.IndexOf(',') + 1;
  536. string str = _DataUrl.Substring(delLength, _DataUrl.Length - delLength);
  537. byte[] bData = Convert.FromBase64String(str);
  538. int iLen = bData.Length;
  539. if (iLen > _MaxSize)
  540. {
  541. _Error = 3;
  542. return;
  543. }
  544. try
  545. {
  546. if (!Directory.Exists(_SavePath)) Directory.CreateDirectory(_SavePath);
  547. string FName;
  548. FName = FileName(".jpg");
  549. string TempFile = "";
  550. if (_IsDraw)
  551. {
  552. TempFile = FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString();
  553. }
  554. else
  555. {
  556. TempFile = FName;
  557. }
  558. FileStream newFile = new FileStream(_SavePath + TempFile, FileMode.Create);
  559. newFile.Write(bData, 0, bData.Length);
  560. newFile.Flush();
  561. int _FileSizeTemp = iLen;
  562. string ImageFilePath = _SavePath + FName;
  563. if (_IsDraw)
  564. {
  565. if (_DrawStyle == 0)
  566. {
  567. System.Drawing.Image Img1 = System.Drawing.Image.FromStream(newFile);
  568. Graphics g = Graphics.FromImage(Img1);
  569. g.DrawImage(Img1, 100, 100, Img1.Width, Img1.Height);
  570. Font f = new Font(_Font, _FontSize);
  571. Brush b = new SolidBrush(Color.Red);
  572. string addtext = _AddText;
  573. g.DrawString(addtext, f, b, _DrawString_x, _DrawString_y);
  574. g.Dispose();
  575. Img1.Save(ImageFilePath);
  576. Img1.Dispose();
  577. }
  578. else
  579. {
  580. System.Drawing.Image image = System.Drawing.Image.FromStream(newFile);
  581. System.Drawing.Image copyImage = System.Drawing.Image.FromFile(_CopyIamgePath);
  582. Graphics g = Graphics.FromImage(image);
  583. g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width - 5, image.Height - copyImage.Height - 5, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
  584. g.Dispose();
  585. image.Save(ImageFilePath);
  586. image.Dispose();
  587. }
  588. }
  589. //获取图片的高度和宽度
  590. System.Drawing.Image Img = System.Drawing.Image.FromStream(newFile);
  591. _Width = Img.Width;
  592. _Height = Img.Height;
  593. //生成缩略图部分
  594. if (_IsCreateImg)
  595. {
  596. #region 缩略图大小只设置了最大范围,并不是实际大小
  597. float realbili = (float)_Width / (float)_Height;
  598. float wishbili = (float)_sWidth / (float)_sHeight;
  599. //实际图比缩略图最大尺寸更宽矮,以宽为准
  600. if (realbili > wishbili)
  601. {
  602. _sHeight = (int)((float)_sWidth / realbili);
  603. }
  604. //实际图比缩略图最大尺寸更高长,以高为准
  605. else
  606. {
  607. _sWidth = (int)((float)_sHeight * realbili);
  608. }
  609. #endregion
  610. this.OutThumbFileName = FName.Split('.').GetValue(0).ToString() + "_s." + FName.Split('.').GetValue(1).ToString();
  611. string ImgFilePath = _SavePath + this.OutThumbFileName;
  612. System.Drawing.Image newImg = Img.GetThumbnailImage(_sWidth, _sHeight, null, System.IntPtr.Zero);
  613. newImg.Save(ImgFilePath);
  614. newImg.Dispose();
  615. _Iss = true;
  616. }
  617. if (_IsDraw)
  618. {
  619. if (File.Exists(_SavePath + FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString()))
  620. {
  621. newFile.Dispose();
  622. File.Delete(_SavePath + FName.Split('.').GetValue(0).ToString() + "_temp." + FName.Split('.').GetValue(1).ToString());
  623. }
  624. }
  625. newFile.Close();
  626. newFile.Dispose();
  627. _OutFileName = FName;
  628. _FileSize = _FileSizeTemp;
  629. _Error = 0;
  630. return;
  631. }
  632. catch
  633. {
  634. _Error = 4;
  635. return;
  636. }
  637. }
  638. #endregion
  639. #region url下载文件并保存本地
  640. public string downloadurl(string url, string filename)
  641. {
  642. try
  643. {
  644. WebClient mywebclient = new WebClient();
  645. byte[] Bytes = mywebclient.DownloadData(url);
  646. if (!Directory.Exists(_SavePath)) Directory.CreateDirectory(_SavePath);
  647. using (var fs = new FileStream(_SavePath + filename, FileMode.Create))
  648. {
  649. fs.Write(Bytes, 0, Bytes.Length);
  650. fs.Flush();
  651. return "";
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. return ex.Message;
  657. }
  658. }
  659. #endregion
  660. }
  661. }