public static UploadSupportingFileResponse UploadSupportingFileHandler(string filename, string description, string pid, string newfilename) { APIWrapper api = null; if (Membership.GetUser() != null && Membership.GetUser().IsApproved) { api = new APIWrapper(Membership.GetUser().UserName, null); } else { api = new APIWrapper(vwarDAL.DefaultUsers.Anonymous[0], null); } UploadSupportingFileResponse response = new UploadSupportingFileResponse(false); try { using (FileStream stream = new FileStream(HostingEnvironment.MapPath(String.Format("~/App_Data/imageTemp/{0}", newfilename)), FileMode.Open)) { byte[] data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); string result = api.UploadSupportingFile(data, pid, filename, description, "00-00-00"); if (result == "Ok") { response = new UploadSupportingFileResponse(true); response.Description = description; response.Filename = filename; } } File.Delete(HostingEnvironment.MapPath(String.Format("~/App_Data/imageTemp/{0}", newfilename))); } catch (System.IO.FileNotFoundException t) { } return(response); }
public static UploadSupportingFileResponse UploadSupportingFileHandler(string filename, string description, string pid, string newfilename) { APIWrapper api = null; if (Membership.GetUser() != null && Membership.GetUser().IsApproved) api = new APIWrapper(Membership.GetUser().UserName, null); else api = new APIWrapper(vwarDAL.DefaultUsers.Anonymous[0], null); UploadSupportingFileResponse response = new UploadSupportingFileResponse(false); try { using (FileStream stream = new FileStream(HostingEnvironment.MapPath(String.Format("~/App_Data/imageTemp/{0}", newfilename)), FileMode.Open)) { byte[] data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); string result = api.UploadSupportingFile(data, pid, filename, description, "00-00-00"); if (result == "Ok") { response = new UploadSupportingFileResponse(true); response.Description = description; response.Filename = filename; } } File.Delete(HostingEnvironment.MapPath(String.Format("~/App_Data/imageTemp/{0}", newfilename))); } catch (System.IO.FileNotFoundException t) { } return response; }