-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddPost.aspx.cs
More file actions
84 lines (71 loc) · 2.98 KB
/
Copy pathAddPost.aspx.cs
File metadata and controls
84 lines (71 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class AddPost : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string authoremail = Session["Email_ID"].ToString();
UserBLL ub = new UserBLL();
int userid = ub.ShowUserID(authoremail);
lblShowID.Text = userid.ToString();
}
protected void btnAddPost_Click(object sender, EventArgs e)
{
int userid = Convert.ToInt16(lblShowID.Text);
int categoryid = Convert.ToInt16(ddlCategory.SelectedValue);
string postcontent = txtPostContent.Text;
DateTime published = DateTime.Now;
string status = "posted";
string image;
if (FileUpload1.PostedFile.ContentLength < 800000)
{
string fileFullname = this.FileUpload1.FileName;
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
// string type = fileFullname.Substring(fileFullname.LastIndexOf(".") , 3);
string type = fileFullname;
//string strFileName = DateTime.Now.ToString("MM-dd-yyyy_HHmmss");
//string strFileType = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();
// string type = strFileName.Substring(strFileName.LastIndexOf(".") + 1);
type = type.Substring(type.Length - 3);
if (type == "bmp" || type == "jpg" || type == "gif" || type == "JPG" || type == "BMP" || type == "GIF")
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/blog") + "\\" + dataName + "." + type);
// FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/" + fileName + type));
image = "~/images/blog/" + dataName + "." + type;
PostBLL pb = new PostBLL();
int i= pb.NewPost(categoryid, userid,postcontent,published,status,image);
if (i > 0)
{
Response.Write("<script language='javascript'>alert('Your post has been added !');</script>");
Response.Redirect("ViewMyPost.aspx");
}
else
{
Response.Write("<script language='javascript'>alert('Your post is failed to be added !');</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('Support format:|jpg|gif|bmp| !');</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('Your image exceeds 800K!');</script>");
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
txtPostContent.Text = "";
}
}