예제 #1
0
        public string GetHtmlAfterTransformData()
        {
            try
            {
                // Get Onedrive file download address.
                Stream req = Request.InputStream;
                req.Seek(0, SeekOrigin.Begin);
                string      json        = new StreamReader(req).ReadToEnd();
                InputObject inputOjbect = null;
                try
                {
                    inputOjbect = JsonConvert.DeserializeObject <InputObject>(json);
                }
                catch (Exception)
                {
                    return(string.Empty);
                }

                string downloadUri = inputOjbect.Downloaduri;
                string accessToken = inputOjbect.AccessToken;
                string fileId      = inputOjbect.FileId;

                // Download the file in Onedrive.
                var    webclient = new WebClient();
                byte[] data      = webclient.DownloadData(downloadUri);

                // Get the file name.
                var fileName = webclient.ResponseHeaders.GetValues("Content-Disposition").FirstOrDefault();
                fileName = fileName.Replace("\"", "");
                var parse = new WriteRawDataToFile();
                if (fileName.ToLower().EndsWith(".docx"))
                {
                    parse = new WordParse(data, accessToken, fileId);
                }
                else if (fileName.ToLower().EndsWith(".xlsx"))
                {
                    parse = new ExcelParse(data, accessToken, fileId);
                }
                else if (fileName.ToLower().EndsWith(".pptx"))
                {
                    parse = new PowerPointParse(data, accessToken, fileId);
                }
                else
                {
                    return(string.Empty);
                }

                return(parse.TempDataToHtmlAndUploadToOneDrive());
            }
            catch (Exception x)
            {
                Response.StatusCode = 400;
                return(x.Message);
            }
        }
예제 #2
0
        public string GetHtmlAfterTransformData()
        {
            string downloadUri = this.Request.QueryString["downloaduri"];

            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();

            InputObject inputOjbect = null;

            try
            {
                inputOjbect = JsonConvert.DeserializeObject <InputObject>(json);
            }
            catch (Exception)
            {
                return(String.Empty);
            }

            string accessToken = inputOjbect.AccessToken;
            string fileId      = inputOjbect.FileId;

            var webclient = new WebClient();

            byte[] data     = webclient.DownloadData(downloadUri);
            var    fileName = webclient.ResponseHeaders.GetValues("Content-Disposition").FirstOrDefault();

            var parse = new WriteToFile();

            if (fileName.ToLower().Contains(".doc") || fileName.ToLower().Contains(".docx"))
            {
                parse = new WordParse(data, accessToken, fileId);
            }
            else if (fileName.ToLower().Contains(".xls") || fileName.ToLower().Contains(".xlsx"))
            {
                parse = new ExcelParse(data, accessToken, fileId);
            }
            else if (fileName.ToLower().Contains(".ppt") || fileName.ToLower().Contains(".pptx"))
            {
                parse = new PowerPointParse(data, accessToken, fileId);
            }
            else
            {
                return(String.Empty);
            }

            return(parse.TempDataToHtml());
        }