public async Task <ActionResult> Index(string type, string file, string key)
        {
            if (type.isNOEOW() || file.isNOEOW() || key.isNOEOW())
            {
                return(BadRequest(new ApiResultError(400, "Type and File and Key is required")));
            }
            var data = await _storage.GetRepository <IFileStore_Images_Repository>().GetAsync(x => x.is_active == true && x.name.Equals(file) && x.check_sum.Equals(key));

            if (data == null)
            {
                return(BadRequest(new ApiResultError(400, "Data not found")));
            }
            string path;

            if (data.is_public)
            {
                path = $@"{_appSetting.PublicDirectory}\{_appSetting.FileStoreFolder}\{data.module}\{type}\";
            }
            else
            {
                path = $@"{AppContext.BaseDirectory}{_appSetting.FileStoreFolder}\{data.module}\{type}\";
            }
            var image = System.IO.File.OpenRead(path + data.name);

            return(File(image, MimeTypes.GetContentType(data.name)));
        }
Example #2
0
        private void btnPptClick(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.ShowDialog();
            String src         = op.FileName;
            var    contentType = MimeTypes.GetContentType(src);

            if (contentType != "application/mspowerpoint")
            {
                string msg = "源文件应为powerpoint文件";
                MessageBox.Show(msg);
                return;
            }
            String    outputFile = String.Concat(src, ".pdf");
            Converter converter  = new PowerPointConverter();

            tryConvert(converter, src, outputFile);
        }
Example #3
0
        public HttpResponseMessage POST()
        {
            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var httpPostedFile = HttpContext.Current.Request.Files["file"];
                var filename       = httpPostedFile.FileName;

                bool folderExists = Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/UploadFiles/images/images"));
                if (!folderExists)
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/UploadFiles/images/images"));
                }
                var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/UploadFiles/images/images"), filename);

                httpPostedFile.SaveAs(fileSavePath);

                var contentType = MimeTypes.GetContentType(fileSavePath);
                if (!contentType.StartsWith("image"))
                {
                    if (File.Exists(fileSavePath))
                    {
                        File.Delete(fileSavePath);
                    }
                    return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
                var responseObj = new
                {
                    fileName = "/Content/UploadFiles/images/images/" + filename
                };
                if (!WebTools.CreateThumbnail(filename, "/Content/UploadFiles/images/images/", 300, 178, false))
                {
                    return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, responseObj));
            }
            return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
        }
        static void Main(string[] args)
        {
            //try
            //{

            string Basepath    = @"C:\Users\tturner\Dropbox\IFTTT\hotredditwallpaper\";
            string NewFilePath = "";
            string DirPath     = "";



            DirectoryInfo dir = new DirectoryInfo(Basepath);


            FileInfo[] files = dir.GetFiles();



            foreach (FileInfo file in files)
            {
                string Oldfilepath = Basepath + file.Name;

                // Console.WriteLine(Basepath+file.Name);
                // Console.WriteLine(filepaths[i]);
                if (File.Exists(Oldfilepath))
                {
                    var content = MimeTypes.GetContentType(Oldfilepath);
                    if (content.StartsWith("image"))
                    {
                        Image img = Image.FromFile(Oldfilepath);


                        if (img.Width >= 1600 && img.Width <= 1700)
                        {
                            NewFilePath = @"C:\Users\tturner\Dropbox\IFTTT\WorkWallpapers";
                        }
                        else if (img.Width >= 1900 && img.Width <= 2000)
                        {
                            NewFilePath = @"C:\Users\tturner\Dropbox\IFTTT\HomeWallpapers";
                        }
                        else
                        {
                            NewFilePath = "delete";
                        }

                        /*
                         * //string directory = @"C:\Users\tturner\Dropbox\IFTTT\";
                         * // string DirectoryName = img.Width + "X" + img.Height;
                         * // string filename = string.Format("{0:yyyy-MM-dd}__{1}", DateTime.Now, "TransferLog.txt");
                         * // string Dirpath = Path.Combine(directory, DirectoryName);
                         *
                         * if (!Directory.Exists(DirectoryName))
                         * {
                         *  System.IO.Directory.CreateDirectory(Dirpath);
                         * }
                         * */
                        DirPath = Path.Combine(NewFilePath, file.Name);
                        img.Dispose();
                        if (NewFilePath != "delete" && File.Exists(DirPath) == false)
                        {
                            Console.WriteLine("saving too " + DirPath);
                            System.IO.File.Move(Oldfilepath, DirPath);
                        }
                        else
                        {
                            DeleteFile(Oldfilepath);
                        }
                    }
                }
            }
        }
Example #5
0
        protected void btnUploadFile_Click(object sender, EventArgs e)
        {
            string errormessage1 = "";

            if (fuPDCADocument.HasFile)
            {
                try
                {
                    if (this.txtDocumentTitle.Text == "" || this.txtDocumentDescription.Text == "")
                    {
                        this.lblDocumentsError.Text = "Document Title and Document Description must be entered.";
                    }
                    else
                    {
                        string filename = Path.GetFileName(fuPDCADocument.FileName);
                        PDCAFile = Server.MapPath("~/") + filename;

                        //lblFileName.Text = Server.MapPath("~/") + filename;
                        //fuPDCADocument.SaveAs(Server.MapPath("~/") + filename);
                        //FileStream fs = new FileStream(Server.MapPath("~/") + filename, FileMode.Open, FileAccess.Read);
                        //BinaryReader br = new BinaryReader(fs);
                        //int numBytes = (int)new FileInfo(Server.MapPath("~/") + filename).Length;
                        //byte[] buff = br.ReadBytes(numBytes);

                        lblFileName.Text = PDCAFile;
                        fuPDCADocument.SaveAs(PDCAFile);
                        string PDCAFileExtension = Path.GetExtension(fuPDCADocument.FileName);

                        // check whether or not the uploaded file is an image:
                        var contentType = MimeTypes.GetContentType(fuPDCADocument.PostedFile.FileName);
                        //if (contentType.StartsWith("image"))
                        //{
                        //    // do something with the image ...
                        //}
                        FileStream   fs       = new FileStream(PDCAFile, FileMode.Open, FileAccess.Read);
                        BinaryReader br       = new BinaryReader(fs);
                        int          numBytes = (int)new FileInfo(PDCAFile).Length;
                        byte[]       buff     = br.ReadBytes(numBytes);
                        //byte[] fileData = File.ReadAllBytes(PDCAFile);

                        try
                        {
                            string     insertQuery2   = @"PDCADocuments_Insert ";
                            SqlCommand insertCommand2 = new SqlCommand(insertQuery2, connection);
                            insertCommand2.CommandType = CommandType.StoredProcedure;
                            insertCommand2.Parameters.Add("PDCAID", SqlDbType.Int).Value = this.txtPDCAID.Text;
                            insertCommand2.Parameters.Add("@DocumentName", SqlDbType.VarChar, 1000).Value = filename;
                            insertCommand2.Parameters.Add("@FileExtension", SqlDbType.VarChar, 50).Value  = PDCAFileExtension;
                            insertCommand2.Parameters.Add("@DocumentType", SqlDbType.VarChar, 50).Value   = contentType;
                            insertCommand2.Parameters.Add("@Title", SqlDbType.VarChar, 2000).Value        = this.txtDocumentTitle.Text;
                            insertCommand2.Parameters.Add("@Description", SqlDbType.VarChar, 2000).Value  = this.txtDocumentDescription.Text;
                            insertCommand2.Parameters.Add("@DocumentFS", SqlDbType.VarBinary).Value       = buff;

                            insertCommand2.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            errormessage1  = ex.Message.ToString();
                            errormessage1 += "";
                            //lblResults.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                        }

                        //lblResults.Text = "Upload status: File uploaded!";
                        this.txtDocumentTitle.Text       = "";
                        this.txtDocumentDescription.Text = "";
                        //this.fuPDCADocument. = "";
                        LoadGridData();
                        BindGrid();
                    }
                }
                catch (Exception ex)
                {
                    errormessage1  = ex.Message.ToString();
                    errormessage1 += "";
                    //lblResults.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }