markus / FileSave / FileUploadWevService / FileUpload.asmx.cs @ b6c25f7a
이력 | 보기 | 이력해설 | 다운로드 (2.83 KB)
1 | f714bef8 | djkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Drawing; |
||
4 | using System.IO; |
||
5 | using System.Linq; |
||
6 | using System.Web; |
||
7 | using System.Web.Services; |
||
8 | |||
9 | namespace FileUploadWevService |
||
10 | { |
||
11 | /// <summary> |
||
12 | /// FileUpload의 요약 설명입니다. |
||
13 | /// </summary> |
||
14 | [WebService(Namespace = "http://tempuri.org/")] |
||
15 | [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
||
16 | [System.ComponentModel.ToolboxItem(false)] |
||
17 | // ASP.NET AJAX를 사용하여 스크립트에서 이 웹 서비스를 호출하려면 다음 줄의 주석 처리를 제거합니다. |
||
18 | // [System.Web.Script.Services.ScriptService] |
||
19 | public class FileUpload : System.Web.Services.WebService |
||
20 | { |
||
21 | |||
22 | [WebMethod] |
||
23 | //public string Run(string ProjectNo, string VPNo, string UserID, string FileName, byte[] imageBytes) |
||
24 | public string Run(string ProjectNo, string VPNo, string UserID, string FileName, byte[] f) |
||
25 | { |
||
26 | KCOMDataModel.DataModel.KCOMEntities entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()); |
||
27 | |||
28 | var item = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault(); |
||
29 | string result = ""; |
||
30 | if (item!=null) |
||
31 | { |
||
32 | result = string.Format(@"{0}/UserData/{1}/{2}/{3}", item.VALUE, ProjectNo, UserID, FileName); |
||
33 | } |
||
34 | else |
||
35 | { |
||
36 | result = string.Format("http://165.244.178.145:5977/UserData/{0}/{1}/{2}", ProjectNo, UserID, FileName); |
||
37 | } |
||
38 | |||
39 | try |
||
40 | { |
||
41 | string DirectoryPath = string.Format(@"D:\TileSource\UserData\{0}\{1}", ProjectNo, UserID); |
||
42 | DirectoryInfo directoryInfo_ = new DirectoryInfo(DirectoryPath); |
||
43 | |||
44 | if (!directoryInfo_.Exists) |
||
45 | { |
||
46 | directoryInfo_.Create(); |
||
47 | } |
||
48 | //Image imageinfo = Converter(base64String); |
||
49 | |||
50 | MemoryStream ms = new MemoryStream(f); |
||
51 | FileStream fs = new FileStream(directoryInfo_ + @"\" + FileName, FileMode.Create); |
||
52 | ms.WriteTo(fs); |
||
53 | |||
54 | ms.Close(); |
||
55 | fs.Close(); |
||
56 | fs.Dispose(); |
||
57 | //imageinfo.Save(DirectoryPath + @"\" + FileName + "png", System.Drawing.Imaging.ImageFormat.Png); |
||
58 | } |
||
59 | catch (Exception ex) |
||
60 | { |
||
61 | result = ex.ToString(); |
||
62 | } |
||
63 | |||
64 | return result; |
||
65 | } |
||
66 | |||
67 | public Image Converter(string base64String) |
||
68 | { |
||
69 | byte[] imageBytes = Convert.FromBase64String(base64String); |
||
70 | |||
71 | using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) |
||
72 | { |
||
73 | Image image = Image.FromStream(ms, true); |
||
74 | return image; |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | } |