Beispiel #1
0
    private void SubmitNewImagePost()
    {
        LS  Controller = new LS();
        int PostID     = 0;

        if (ImageFU.HasFiles)
        {
            // Add the post to the db and retrieve the PostID
            PostID = Controller.CreatePost("testuser", DateTime.Now, TitleTB.Text, "", true, null, true);

            // Create folder to store image for new main post
            string path = @"~/Images/PostID" + PostID.ToString() + @"/";

            if (!System.IO.Directory.Exists(Server.MapPath(@"~/Images/PostID" + PostID.ToString() + @"/")))
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(path));
            }

            // Save image locally and store file path for each image
            foreach (HttpPostedFile file in ImageFU.PostedFiles)
            {
                file.SaveAs(Server.MapPath(path + file.FileName));
                Controller.AddImage(PostID, path + file.FileName);
            }

            Response.Redirect("~/Default.aspx");
        }
    }
Beispiel #2
0
        // This is how we store images locally
        protected void Test_Click(object sender, EventArgs e)
        {
            if (!UI_FUL_Image.HasFiles)
            {
                Response.Write("No file selected");
                return;
            }

            int PostID = 3;

            if (UI_FUL_Image.HasFiles)
            {
                string path = @"~/Images/PostID" + PostID.ToString() + @"/";
                if (!System.IO.Directory.Exists(Server.MapPath(@"~/Images/PostID" + PostID.ToString() + @"/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(path));
                }

                UI_FUL_Image.SaveAs(Server.MapPath(path + UI_FUL_Image.FileName));
                LS Controller = new LS();

                bool Confirmation = Controller.AddImage(PostID, path + UI_FUL_Image.FileName);
                Response.Write(Confirmation);
            }
        }