-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileUpLoad.aspx.cs
107 lines (97 loc) · 3.58 KB
/
FileUpLoad.aspx.cs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class MoosigiUpLoad : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
if (int.Parse(Session["UserTypeID"].ToString()) == 1)
{
if (!IsPostBack)
{
//grdFill();
string UpPath;
UpPath = Server.MapPath("UploadedUserFiles");
if (!IsPostBack)
{
cmbFill();
}
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(UpPath);
}
}
}
else
{
Response.Redirect("Default.aspx?ID=NotHavePermission" + DateTime.Now.Ticks.ToString());
}
}
else
{
Response.Redirect("Default.aspx?ID=NotHavePermission" + DateTime.Now.Ticks.ToString());
}
}
protected void cmbFill()
{
FirstClass db = new FirstClass();
DataTable dt = new DataTable();
dt = db.dbOut("SELECT TOP 100 PERCENT NewsID, NewsTitle FROM tblNews ORDER BY NewsTitle DESC");
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "NewsTitle";
DropDownList1.DataValueField = "NewsID";
DropDownList1.DataBind();
}
private string GetNameForFile()
{
FirstClass db = new FirstClass();
string DateNow = db.dtShamsi();
DateNow = DateNow.Replace("/", "");
DateNow += DateTime.Now.Hour.ToString().Trim() + DateTime.Now.Minute.ToString().Trim() + DateTime.Now.Second.ToString().Trim();
return DateNow.Trim();
}
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileField.HasFile)
{
FileName.InnerHtml = FileField.PostedFile.FileName;
FileContent.InnerHtml = FileField.PostedFile.ContentType;
FileSize.InnerHtml = FileField.PostedFile.ContentLength.ToString();
UploadDetails.Visible = true;
string MyFileName = FileField.PostedFile.FileName;
string c = GetNameForFile() + "_" + System.IO.Path.GetFileName(MyFileName);
try
{
FileField.PostedFile.SaveAs(Server.MapPath("UploadedUserFiles\\") + c);
//FileField.PostedFile.SaveAs("\\UploadedUserFiles\\" + c);
dbIns("UploadedUserFiles\\" + c);
Span1.InnerHtml = "File Uploaded Succeded.";
}
catch
{
Span1.InnerHtml = "File Uploaded Field";
UploadDetails.Visible = false;
}
}
else
{
Span1.InnerHtml = "File Uploaded Field";
UploadDetails.Visible = false;
}
}
protected void dbIns(string myMusicPath)
{
FirstClass db = new FirstClass();
db.exeCommand1("INSERT INTO tblMusics (MusicArticleID, MusicDescription, KhanadehName, MusicPathFile) VALUES ('" + DropDownList1.SelectedValue + "', '" + TextBox1.Text.Trim() + "', '" + TextBox2.Text.Trim() + "', '" + myMusicPath + "' )");
}
}