-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebForm1.aspx.cs
More file actions
175 lines (137 loc) · 5.97 KB
/
WebForm1.aspx.cs
File metadata and controls
175 lines (137 loc) · 5.97 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Net.Mail;
using System.Net.Http;
using System.Data.SqlClient;
namespace excel
{
public partial class WebForm1 : System.Web.UI.Page
{
String ExcelPath = "";
protected void Page_Load(object sender, EventArgs e)
{
p2.Visible = false;
ExcelPath = Server.MapPath("~/ExcelFile/") + Session["path"].ToString();
OleDbConnection mycon = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0; Persist Security Info = False");
mycon.Open();
OleDbCommand cmd = new OleDbCommand(@"select * from [Sheet1$]", mycon);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
mycon.Close();
Excel.Application excelApp = new Excel.Application();
Workbook wb;
Worksheet ws;
// string Path = @"C:\Users\Hp\Documents\visual studio 2015\Projects\excel\excel\ExcelFile\" + Session["path"].ToString();
string Path = Server.MapPath("~/ExcelFile/") + Session["path"].ToString();
wb = excelApp.Workbooks.Open(Path);
ws = wb.Worksheets[1];
ws.Cells[1, 2].Value = "Website Status";
ws.Cells[1, 3].Value = "Website Status Code";
int i = 2, j = 2, k = 3;
while (ws.Cells[i, 1].Value != null)
{
try
{
HttpClient client = new HttpClient();
var Url = ws.Cells[i++, 1].Value.ToString();
Uri urlCheck = new Uri(Url);
var client1 = new SmtpClient();
var res = client.GetAsync(urlCheck).Result;
var statusCode = res.StatusCode; //should be 404
// MessageBox.Show(statusCode.ToString() + ' ' + (int)statusCode);
ws.Cells[i - 1, j] = statusCode.ToString();
ws.Cells[i - 1, k] = (int)statusCode;
wb.Save();
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
ws.Cells[i - 1, j] = "None";
ws.Cells[i - 1, k] = "None";
// wb.Save();
}
}
wb.Save();
wb.Close(1);
excelApp.Quit();
OleDbConnection mycon1 = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0; Persist Security Info = False");
mycon1.Open();
OleDbCommand cmd2 = new OleDbCommand(@"select * from [Sheet1$]", mycon1);
OleDbDataAdapter da1 = new OleDbDataAdapter();
da1.SelectCommand = cmd2;
DataSet ds1 = new DataSet();
da1.Fill(ds1);
GridView1.DataSource = ds1.Tables[0];
GridView1.DataBind();
mycon1.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
FileInfo file = new FileInfo(ExcelPath);
if (file.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + Session["path"].ToString());
Response.AddHeader("Content-Type", "application/Excel");
Response.ContentType = "application/vnd.xls";
Response.AddHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.End();
}
else
{
MessageBox.Show("This file does not exist.");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
// Specify the from and to email address
MailMessage mailMessage = new MailMessage("altson.ecommerce@gmail.com", TextBox1.Text);
// Specify the email body
mailMessage.Body = "Hi " + TextBox3.Text+',' + '\n' + "Welcome to Website Analyzer." + '\n' + "This mail is regarding your download request for file " + Session["path"].ToString() + '\n' + "Please find the attached file below";
// Specify the email Subject
mailMessage.Subject = "Website|Analyzer File Download";
if (!string.IsNullOrEmpty(ExcelPath))
{
Attachment attach = new Attachment(ExcelPath);
mailMessage.Attachments.Add(attach);
}
// Specify the SMTP server name and post number
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
// Specify your gmail address and password
smtpClient.Credentials = new System.Net.NetworkCredential()
{
UserName = "altson.ecommerce@gmail.com",
Password = "techbees"
};
// Gmail works on SSL, so set this property to true
smtpClient.EnableSsl = true;
// Finall send the email message using Send() method
smtpClient.Send(mailMessage);
p2.Visible = true;
}
catch (Exception ex)
{
p2.Visible = true;
p2.InnerHtml = "Please try with another email....";
}
}
}
}