示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Dictionary <String, FileFormat> nl = new Dictionary <String, FileFormat>();

        nl.Add(".ppt", FileFormat.PPT);
        nl.Add(".pptx", FileFormat.Pptx2010);

        var presentationname = Request.Form["pname"];
        var metatag          = Request.Form["metatag"];
        var categoryid       = Request.Form["categoryid"];
        var folderid         = Request.Form["folderid"];
        var file             = Request.Files["file"];

        if (file != null)
        {
            String ext = System.IO.Path.GetExtension(file.FileName).ToLower();

            DataCommand command = new DataCommand("createPresentation");
            command.Add("presentationname", presentationname);
            command.Add("categoryid", Convert.ToUInt64(categoryid));
            command.Add("metatag", metatag);
            command.Add("folderid", Convert.ToUInt64(folderid));
            command.Add("description", "No desc");
            command.Add("type", ext);

            DataSet   ds = (DataSet)command.Execute(true);
            DataTable dt = ds.Tables[0];

            String presentatonId = dt.Rows[0]["presentationid"].ToString();

            file.SaveAs(Server.MapPath("~/Uploads/" + presentatonId + ext));

            try
            {
                Presentation presentation = new Presentation();
                presentation.LoadFromStream(file.InputStream, nl[ext]);
                var totalSlide = presentation.Slides.Count - 1;
                //traverse the slides of PPT files
                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    ISlide slide = presentation.Slides[i];

                    String title = getTitle(slide);
                    title = title == null ? "No Title" : title;
                    DataCommand command1 = new DataCommand("createSlide");
                    command1.Add("slidename", title);
                    command1.Add("presentationid", presentatonId);
                    command1.Add("slideindex", i);

                    DataSet   ds1 = (DataSet)command1.Execute(true);
                    DataTable dt1 = ds1.Tables[0];

                    String slideId = dt1.Rows[0]["slideid"].ToString();

                    //save the slide to Image
                    Image image = slide.SaveAsImage(960, 720);

                    String fileName = Server.MapPath("~/Uploads/Images/" + String.Format(slideId + ".jpeg", i));
                    image.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                    Image imageT = slide.SaveAsImage(320, 240);

                    fileName = Server.MapPath("~/Uploads/Thumbnails/" + String.Format(slideId + ".jpeg", i));
                    imageT.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                    Int32 precentageComplete = (i / totalSlide) * 100;
                    updatePresentationStatus(0, precentageComplete, presentatonId);
                }
                updatePresentationStatus(1, 100, presentatonId);
                Response.Write("Success");
            }
            catch (Exception ex)
            {
                updatePresentationStatus(2, 0, presentatonId);
                Response.Write(ex.Message);
            }
        }
    }