public static void SendFileSync(FileSyncInput input) { try { string PicTempAPIURL = System.Web.Configuration.WebConfigurationManager.AppSettings["PicTempAPIURL"]; var serializer = new JavaScriptSerializer(); var jsonText = serializer.Serialize(input); var jsonBytes = Encoding.UTF8.GetBytes(jsonText); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(PicTempAPIURL); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/json"; request.ContentLength = jsonBytes.Length; using (var requestStream = request.GetRequestStream()) { requestStream.Write(jsonBytes, 0, jsonBytes.Length); requestStream.Flush(); } } catch (Exception) { } }
public static void SaveFileToDB(string filePath) { byte[] fileBytes; using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (var reader = new BinaryReader(stream)) { fileBytes = reader.ReadBytes((int)stream.Length); } } string fileName = Path.GetFileName(filePath); SSoft.Data.SqlHelper.SelectNonQuery("INSERT INTO FileTempPath (FileName,FileContent) VALUES (@FileName,@FileContent)", new SqlParameter[] { new SqlParameter("@FileName", fileName), new SqlParameter("@FileContent", fileBytes) }, System.Web.Configuration.WebConfigurationManager.ConnectionStrings["FubonPicTempDBConnectionString"].ConnectionString); FileSyncInput fileSyncInput = new FileSyncInput(); fileSyncInput.SyncType = 0; fileSyncInput.PicNO = new ArrayList(); fileSyncInput.PicNO.Add(fileName); SendFileSync(fileSyncInput); }