Beispiel #1
0
        public async Task <HttpResponseMessage> SetFileAttributes()
        {
            if (!Request.Content.IsFormData())
            {
                return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
                // HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType);
            }

            string authorizationString = DecodeAuthorizationString();

            SPHelper.SetSharePointCredentials(authorizationString);
            NameValueCollection formData = await Request.Content.ReadAsFormDataAsync();

            if (formData.Keys.Count > 0)
            {
                SharePointDocument doc = new SharePointDocument();
                doc.FileId       = formData.Get("FileId").ToGuid();
                doc.MasterId     = formData.Get("MasterId");
                doc.MasterNumber = formData.Get("MasterNumber");
                doc.DocumentType = StringToLookupItem("DocumentType", formData.Get("DocumentType"));
                doc.MasterName   = formData.Get("MasterName");

                ListItem file = SPHelper.FindFile(doc.FileId);
                SPHelper.AddDocumentProperties(file, doc);
            }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Beispiel #2
0
        public HttpResponseMessage DeleteFile(string id)
        {
            string authorizationString = DecodeAuthorizationString();

            SPHelper.SetSharePointCredentials(authorizationString);

            ListItem item = SPHelper.FindFile(id.ToGuid());

            SPHelper.DeleteFile(item);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Beispiel #3
0
        public HttpResponseMessage DownloadFile([FromUri] string id)
        {
            string authorizationString = DecodeAuthorizationString();

            SPHelper.SetSharePointCredentials(authorizationString);

            ListItem item = SPHelper.FindFile(id.ToGuid());

            string fileName              = item["FileLeafRef"].ToString();
            string contentType           = System.Web.MimeMapping.GetMimeMapping(fileName);
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            Byte[] bytes = SPHelper.DownloadFile(item);
            response.Content = new ByteArrayContent(bytes);
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentType                 = new MediaTypeHeaderValue(contentType);
            response.Content.Headers.ContentDisposition.FileName = fileName;

            return(response);
        }