public void UploadRequiredFileToSharePoint(int travelRequestId, SharePointUpload sharePointUploadRequest, int requiredFileOrder) { try { var endpointUrl = System.Configuration.ConfigurationManager.AppSettings["sharepointServiceUrl"].ToString() + "/SharePoint/UploadDocument"; // call Sharepoint var client = new HttpClient(); var response = client.PostAsJsonAsync(endpointUrl, sharePointUploadRequest).ConfigureAwait(false); // Save to database documentsRepository.UploadRequiredFileInfo(travelRequestId, sharePointUploadRequest.documentName, requiredFileOrder); } catch (Exception ex) { throw new Exception("Unable to upload the document" + ex.Message); } }
public HttpResponseMessage UploadDocument1(int travelRequestId, int badgeNumber) { IDocumentsService documentsService = new DocumentsService(); HttpResponseMessage msg = null; try { var request = HttpContext.Current.Request; HttpFileCollection allFiles = request.Files; HttpPostedFile uploadedFile = allFiles[0]; FileInfo uploadedFileInfo = new FileInfo(uploadedFile.FileName); String extension = uploadedFileInfo.Extension; int imageLength = uploadedFile.ContentLength; string imageType = uploadedFile.ContentType; byte[] binaryImagedata = new byte[imageLength]; uploadedFile.InputStream.Read(binaryImagedata, 0, imageLength); var endpointUrl = System.Configuration.ConfigurationManager.AppSettings["sharepointServiceUrl"].ToString() + "/SharePoint/UploadDocument"; SharePointUpload uploadRequest = new SharePointUpload() { documentStream = binaryImagedata, siteUrl = "http://mtaspw01/collaboration/InformationManagement/ATMS/apps", documentListName = "TravelApp", documentName = uploadedFile.FileName, folder = badgeNumber.ToString() + "-" + travelRequestId }; documentsService.UploadRequiredFileToSharePoint(travelRequestId, uploadRequest, 1); msg = Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { LogMessage.Log("api/documents/filesupload : " + ex.Message); msg = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unable to upload document "); } return(msg); }