http://www.csharp-examples.net/get-files-from-directory/
Arrays:
http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
Split:
http://dotnetperls.com/string-split
Foreach;
http://msdn.microsoft.com/en-us/library/aa288257(v=vs.71).aspx
strings:
http://msdn.microsoft.com/en-us/library/ms228362.aspx
Functions:
http://csharp.net-tutorials.com/basics/functions/
Try Catch:
http://msdn.microsoft.com/en-us/library/0yd65esw(v=vs.71).aspx
Byval - Byref:
http://www.dotnetspider.com/forum/180058-ByVal-ByRef-example-C-net.aspx
sql
http://www.w3enterprises.com/articles/using.aspx
http://www.codeproject.com/KB/database/sql_in_csharp.aspx
Friday, February 4, 2011
c# - continuing app : Insert Mod.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data.SqlClient;
6
7 namespace PageControlRegistry
8 {
9 class Operations
10 {
11 public int CreateObject(string strSYME_PAGE, string strSYOB_OBJECTNAME, string strSYOB_OBJECTLABEL, int intSYOB_OBJECTTYPE)
12 {
13 SqlCommand cmdcommand = null;
14 Connection modCon;
15 string SQLString;
16 try
17 {
18 modCon = new Connection();
19 cmdcommand = new SqlCommand();
20 cmdcommand.Connection = modCon.runCon();
21 SQLString = "insert into app_menu_object";
22 SQLString += " (SYME_SEQ, SYME_PAGE, SYOB_OBJECTNAME, SYOB_OBJECTLABEL, SYOB_OBJECTTYPE, SYOB_OBJECTTYPEDESC)";
23 SQLString += " SELECT SYME_SEQ, '" + strSYME_PAGE + "', '" + strSYOB_OBJECTNAME + "', '" + strSYOB_OBJECTLABEL + "', ";
24 SQLString += intSYOB_OBJECTTYPE + ", dbo.ITP_GetDescription('OBJ', '" + intSYOB_OBJECTTYPE + "')";
25 SQLString += " FROM app_menu WHERE ACTIVE = 1 AND SYME_URL LIKE '%/" + strSYME_PAGE + "'";
26 cmdcommand.CommandText = SQLString;
27 cmdcommand.ExecuteNonQuery();
28 cmdcommand.Connection.Close();
29 return 0;
30 }
31 catch
32 {
33 if (cmdcommand != null)
34 {
35 cmdcommand.Dispose();
36 }
37 return 1;
38 }
39 }
40 }
41 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data.SqlClient;
6
7 namespace PageControlRegistry
8 {
9 class Operations
10 {
11 public int CreateObject(string strSYME_PAGE, string strSYOB_OBJECTNAME, string strSYOB_OBJECTLABEL, int intSYOB_OBJECTTYPE)
12 {
13 SqlCommand cmdcommand = null;
14 Connection modCon;
15 string SQLString;
16 try
17 {
18 modCon = new Connection();
19 cmdcommand = new SqlCommand();
20 cmdcommand.Connection = modCon.runCon();
21 SQLString = "insert into app_menu_object";
22 SQLString += " (SYME_SEQ, SYME_PAGE, SYOB_OBJECTNAME, SYOB_OBJECTLABEL, SYOB_OBJECTTYPE, SYOB_OBJECTTYPEDESC)";
23 SQLString += " SELECT SYME_SEQ, '" + strSYME_PAGE + "', '" + strSYOB_OBJECTNAME + "', '" + strSYOB_OBJECTLABEL + "', ";
24 SQLString += intSYOB_OBJECTTYPE + ", dbo.ITP_GetDescription('OBJ', '" + intSYOB_OBJECTTYPE + "')";
25 SQLString += " FROM app_menu WHERE ACTIVE = 1 AND SYME_URL LIKE '%/" + strSYME_PAGE + "'";
26 cmdcommand.CommandText = SQLString;
27 cmdcommand.ExecuteNonQuery();
28 cmdcommand.Connection.Close();
29 return 0;
30 }
31 catch
32 {
33 if (cmdcommand != null)
34 {
35 cmdcommand.Dispose();
36 }
37 return 1;
38 }
39 }
40 }
41 }
c# connection.mod - App to save fcontrols from web pages in a folder.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6 using System.Data.SqlClient;
7 namespace PageControlRegistry
8 {
9 class Connection
10 {
11
12 public SqlConnection runCon() {
13 SqlConnection conn = null;
14 try{
15 conn = new SqlConnection(@"Data Source='Mysqldev2005';Initial Catalog='MYDB';User Id='kathy';Password='password';");
16 conn.Open();
17 return conn;
18 }
19 catch{
20 if (conn != null) {
21 conn.Dispose();
22 }
23 return null;
24 }
25 }
26 }
27
28
29
30 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6 using System.Data.SqlClient;
7 namespace PageControlRegistry
8 {
9 class Connection
10 {
11
12 public SqlConnection runCon() {
13 SqlConnection conn = null;
14 try{
15 conn = new SqlConnection(@"Data Source='Mysqldev2005';Initial Catalog='MYDB';User Id='kathy';Password='password';");
16 conn.Open();
17 return conn;
18 }
19 catch{
20 if (conn != null) {
21 conn.Dispose();
22 }
23 return null;
24 }
25 }
26 }
27
28
29
30 }
C# - Application to save controls of web pages in a Folder
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO;
10
11 namespace PageControlRegistry
12 {
13 public partial class Form1 : Form
14 {
15 public Form1()
16 {
17 InitializeComponent();
18 }
19
20 private void button1_Click(object sender, EventArgs e)
21 {
22 string foldername = "";
23 string path = "";
24 string[] options;
25 string[] filesinPath;
26
27
28 int i = 0;
29
30 try
31 {
32 //Cleaning the ListBox
33 listBox1.Items.Clear();
34
35 //Verifying the
36 if (chkSO.Checked == true)
37 {
38 foldername = "NS_So";
39 }
40
41 if (chkProd.Checked == true)
42 {
43 if (foldername.Length > 0)
44 { foldername += "|"; }
45
46 foldername += "NS_Production";
47 }
48
49 options = foldername.Split(new string[] { "|" }, StringSplitOptions.None);
50 for (i = 0; i < options.Length; i++)
51 {
52 path = @"C:\DEV\" + options[i] + @"\Pages";
53 filesinPath = Directory.GetFiles(path, "*.aspx");
54 foreach (string filei in filesinPath)
55 {
56 listBox1.Items.Add(filei);
57 int ival = FolderFilesLookUp(filei);
58 if (ival == 1) return;
59
60 }
61 }
62
63
64
65
66 }
67 catch (Exception ex) {
68 lblError.Text = ex.Message;
69 }
70
71 }
72
73
74 #region Functions
75 //Function
76 private int FolderFilesLookUp(string filei)
77 {
78 string sLine;
79 string sFile;
80 try
81 {
82 FileStream fs = new FileStream(filei, FileMode.Open, FileAccess.Read);
83 StreamReader d = new StreamReader(fs);
84 d.BaseStream.Seek(0, SeekOrigin.Begin);
85 sFile = System.IO.Path.GetFileNameWithoutExtension(filei) + ".aspx";
86
87 while (d.Peek() > -1) {
88 sLine = d.ReadLine();
89
90 if (sLine.IndexOf("<asp:DropDownList") > 0)
91 {
92 if (ControlIDLookUP(sFile, 11, sLine) == 1) return 1;
93 }
94
95 if (sLine.IndexOf("<asp:ListBox") > 0)
96 {
97 if (ControlIDLookUP(sFile, 12, sLine) == 1) return 1;
98 }
99
100 if (sLine.IndexOf("<asp:Label") > 0)
101 {
102 if (ControlIDLookUP(sFile, 3, sLine) == 1) return 1;
103 }
104
105 if (sLine.IndexOf("<asp:TextBox") > 0)
106 {
107 if (ControlIDLookUP(sFile, 5, sLine) == 1) return 1;
108 }
109
110 if (sLine.IndexOf("<asp:ImageButton") > 0)
111 {
112 if (ControlIDLookUP(sFile, 15, sLine) == 1) return 1;
113 }
114
115 if (sLine.IndexOf("<asp:Button") > 0)
116 {
117 if (ControlIDLookUP(sFile, 1, sLine) == 1) return 1;
118 }
119
120 if (sLine.IndexOf("<asp:RadioButton") > 0)
121 {
122 if (ControlIDLookUP(sFile, 7, sLine) == 1) return 1;
123 }
124
125 if (sLine.IndexOf("<asp:RadioButtonList") > 0)
126 {
127 if (ControlIDLookUP(sFile, 13, sLine) == 1) return 1;
128 }
129
130 if (sLine.IndexOf("<asp:CheckBoxList") > 0)
131 {
132 if (ControlIDLookUP(sFile, 14, sLine) == 1) return 1;
133 }
134
135 if (sLine.IndexOf("<telerik:RadComboBox") > 0)
136 {
137 if (ControlIDLookUP(sFile, 10, sLine) == 1) return 1;
138 }
139
140 if (sLine.IndexOf("<telerik:RadNumericTextBox") > 0)
141 {
142 if (ControlIDLookUP(sFile, 6, sLine) == 1) return 1;
143 }
144 }
145
146 return 0;
147 }
148
149 catch (Exception ex)
150 {
151 lblError.Text = ex.Message;
152 return 1;
153 }
154
155 }
156
157 private int ControlIDLookUP(string sFile, int intControlType, string strText)
158 {
159 string sControl;
160 Operations modOper;
161 int iResult;
162 try
163 {
164 modOper = new Operations();
165
166 strText = strText.Substring(strText.IndexOf("ID=") + 4);
167 sControl = strText.Substring(0, strText.IndexOf("\""));
168
169 iResult = modOper.CreateObject(sFile, sControl, "", intControlType);
170
171 return iResult;
172 }
173
174 catch (Exception ex)
175 {
176 lblError.Text = ex.Message;
177 return 1;
178 }
179
180 }
181
182 #endregion
183 }
184
185
186 }
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO;
10
11 namespace PageControlRegistry
12 {
13 public partial class Form1 : Form
14 {
15 public Form1()
16 {
17 InitializeComponent();
18 }
19
20 private void button1_Click(object sender, EventArgs e)
21 {
22 string foldername = "";
23 string path = "";
24 string[] options;
25 string[] filesinPath;
26
27
28 int i = 0;
29
30 try
31 {
32 //Cleaning the ListBox
33 listBox1.Items.Clear();
34
35 //Verifying the
36 if (chkSO.Checked == true)
37 {
38 foldername = "NS_So";
39 }
40
41 if (chkProd.Checked == true)
42 {
43 if (foldername.Length > 0)
44 { foldername += "|"; }
45
46 foldername += "NS_Production";
47 }
48
49 options = foldername.Split(new string[] { "|" }, StringSplitOptions.None);
50 for (i = 0; i < options.Length; i++)
51 {
52 path = @"C:\DEV\" + options[i] + @"\Pages";
53 filesinPath = Directory.GetFiles(path, "*.aspx");
54 foreach (string filei in filesinPath)
55 {
56 listBox1.Items.Add(filei);
57 int ival = FolderFilesLookUp(filei);
58 if (ival == 1) return;
59
60 }
61 }
62
63
64
65
66 }
67 catch (Exception ex) {
68 lblError.Text = ex.Message;
69 }
70
71 }
72
73
74 #region Functions
75 //Function
76 private int FolderFilesLookUp(string filei)
77 {
78 string sLine;
79 string sFile;
80 try
81 {
82 FileStream fs = new FileStream(filei, FileMode.Open, FileAccess.Read);
83 StreamReader d = new StreamReader(fs);
84 d.BaseStream.Seek(0, SeekOrigin.Begin);
85 sFile = System.IO.Path.GetFileNameWithoutExtension(filei) + ".aspx";
86
87 while (d.Peek() > -1) {
88 sLine = d.ReadLine();
89
90 if (sLine.IndexOf("<asp:DropDownList") > 0)
91 {
92 if (ControlIDLookUP(sFile, 11, sLine) == 1) return 1;
93 }
94
95 if (sLine.IndexOf("<asp:ListBox") > 0)
96 {
97 if (ControlIDLookUP(sFile, 12, sLine) == 1) return 1;
98 }
99
100 if (sLine.IndexOf("<asp:Label") > 0)
101 {
102 if (ControlIDLookUP(sFile, 3, sLine) == 1) return 1;
103 }
104
105 if (sLine.IndexOf("<asp:TextBox") > 0)
106 {
107 if (ControlIDLookUP(sFile, 5, sLine) == 1) return 1;
108 }
109
110 if (sLine.IndexOf("<asp:ImageButton") > 0)
111 {
112 if (ControlIDLookUP(sFile, 15, sLine) == 1) return 1;
113 }
114
115 if (sLine.IndexOf("<asp:Button") > 0)
116 {
117 if (ControlIDLookUP(sFile, 1, sLine) == 1) return 1;
118 }
119
120 if (sLine.IndexOf("<asp:RadioButton") > 0)
121 {
122 if (ControlIDLookUP(sFile, 7, sLine) == 1) return 1;
123 }
124
125 if (sLine.IndexOf("<asp:RadioButtonList") > 0)
126 {
127 if (ControlIDLookUP(sFile, 13, sLine) == 1) return 1;
128 }
129
130 if (sLine.IndexOf("<asp:CheckBoxList") > 0)
131 {
132 if (ControlIDLookUP(sFile, 14, sLine) == 1) return 1;
133 }
134
135 if (sLine.IndexOf("<telerik:RadComboBox") > 0)
136 {
137 if (ControlIDLookUP(sFile, 10, sLine) == 1) return 1;
138 }
139
140 if (sLine.IndexOf("<telerik:RadNumericTextBox") > 0)
141 {
142 if (ControlIDLookUP(sFile, 6, sLine) == 1) return 1;
143 }
144 }
145
146 return 0;
147 }
148
149 catch (Exception ex)
150 {
151 lblError.Text = ex.Message;
152 return 1;
153 }
154
155 }
156
157 private int ControlIDLookUP(string sFile, int intControlType, string strText)
158 {
159 string sControl;
160 Operations modOper;
161 int iResult;
162 try
163 {
164 modOper = new Operations();
165
166 strText = strText.Substring(strText.IndexOf("ID=") + 4);
167 sControl = strText.Substring(0, strText.IndexOf("\""));
168
169 iResult = modOper.CreateObject(sFile, sControl, "", intControlType);
170
171 return iResult;
172 }
173
174 catch (Exception ex)
175 {
176 lblError.Text = ex.Message;
177 return 1;
178 }
179
180 }
181
182 #endregion
183 }
184
185
186 }
Tuesday, January 25, 2011
SetValue not working for RadNumericTextbox
Situation:
Setting a RadNumericTextBox's value using a Javascript function was not an issue in previous versions of Telerik. However, once I updated my Telerik Version to v. 2010.3.1109.40. This SetValue property was not working anymore.
Solution:
1) RadNumericTextBox definition in HTML
Very Important:
Be sure to call a Javascript function in one event declared in the ClientEvents tag of the control. In the example: onload event.
2) Javascript code for the function ClientEvents' event:
3)Javascript code to set the value:
Setting a RadNumericTextBox's value using a Javascript function was not an issue in previous versions of Telerik. However, once I updated my Telerik Version to v. 2010.3.1109.40. This SetValue property was not working anymore.
Solution:
1) RadNumericTextBox definition in HTML
1 <telerik:RadNumericTextBox ID="txtTaxCode" runat="server" CssClass="textbox_num_enabled2" Width="40px" MaxLength="4" MinValue="0" MaxValue="9999" EnableEmbeddedSkins="false">
2 <ClientEvents OnLoad="Loadradvalue"/> 3 <NumberFormat DecimalDigits="0" GroupSeparator=""/>
4 </telerik:RadNumericTextBox>
2 <ClientEvents OnLoad="Loadradvalue"/> 3 <NumberFormat DecimalDigits="0" GroupSeparator=""/>
4 </telerik:RadNumericTextBox>
Very Important:
Be sure to call a Javascript function in one event declared in the ClientEvents tag of the control. In the example: onload event.
2) Javascript code for the function ClientEvents' event:
1 function Loadradvalue(sender, args) {
2 radvalue = sender;
3 }
2 radvalue = sender;
3 }
3)Javascript code to set the value:
1 function CallBackFunction(radWindow) {
2 radvalue.set_value(5);
3 }
Now, it works well in my project. More information of properties and methods for Radnumerictextbox and other Telerik controls available here: http://www.telerik.com/help/aspnet-ajax/input_clientsideradnumerictextbox.html
2 radvalue.set_value(5);
3 }
Now, it works well in my project. More information of properties and methods for Radnumerictextbox and other Telerik controls available here: http://www.telerik.com/help/aspnet-ajax/input_clientsideradnumerictextbox.html
Friday, August 13, 2010
Hiding GridEditCommandColumn and CommandItemDisplay
It is not necessary to disable a gridEditCommandColumn in the prerender or databind event of the radgrid or datagrid.
To hide the GridEditCommandColumn:
wgdDetails.Columns.Item(1).Visible = False
To hide the CommandItem (Add)
wgdDetails.MasterTableView.IsItemInserted = False
wgdDetails.MasterTableView.CommandItemDisplay = Telerik.Web.UI.GridCommandItemDisplay.None
To hide the GridEditCommandColumn:
wgdDetails.Columns.Item(1).Visible = False
To hide the CommandItem (Add)
wgdDetails.MasterTableView.IsItemInserted = False
wgdDetails.MasterTableView.CommandItemDisplay = Telerik.Web.UI.GridCommandItemDisplay.None
Tuesday, August 3, 2010
Filter DataTable
Method to filter datatable. Returns a dataset with two datatables (0ne for the filtered data and another one to show any error message defined in the caller method or event)
1 Protected Function FilterDataTable(ByVal strFilterString As String, ByVal dtMainTable As Data.DataTable, ByVal strMessage As String) As Data.DataSet
2 Dim ResultData As New DataSet
3 Dim dtMessage As New Data.DataTable
4 Dim DataTableClon As New Data.DataTable
5 Dim drClon As System.Data.DataRow()
6 Dim dsDataFiltered As New Data.DataSet
7 Try
8 ResultData.Tables.Add(dtMainTable)
9 DataTableClon = ResultData.Tables(0).Copy
10 DataTableClon.Rows.Clear()
11 drClon = ResultData.Tables(0).Select(strFilterString)
12 For Each dr In drClon
13 DataTableClon.ImportRow(dr)
14 Next
15
16 dtMessage.TableName = "Header"
17 dtMessage.Columns.Add("ErrorMessage", GetType(System.String))
18 dsDataFiltered.Tables.Add(DataTableClon)
19 dsDataFiltered.Tables.Add(dtMessage)
20 Dim newMessageRow As DataRow = dsDataFiltered.Tables("Header").NewRow()
21 newMessageRow("ErrorMessage") = strMessage
22 dsDataFiltered.Tables("Header").Rows.Add(newMessageRow)
23
24 Catch ex As Exception
25 Call ManageError(strGlobalUser, strAppName, strModName, "FilterDataTable", intGlobalMain, Err, strGlobalPathError, ApplicationType.Web)
26 Finally
27 FilterDataTable = dsDataFiltered
28 End Try
29 End Function
2 Dim ResultData As New DataSet
3 Dim dtMessage As New Data.DataTable
4 Dim DataTableClon As New Data.DataTable
5 Dim drClon As System.Data.DataRow()
6 Dim dsDataFiltered As New Data.DataSet
7 Try
8 ResultData.Tables.Add(dtMainTable)
9 DataTableClon = ResultData.Tables(0).Copy
10 DataTableClon.Rows.Clear()
11 drClon = ResultData.Tables(0).Select(strFilterString)
12 For Each dr In drClon
13 DataTableClon.ImportRow(dr)
14 Next
15
16 dtMessage.TableName = "Header"
17 dtMessage.Columns.Add("ErrorMessage", GetType(System.String))
18 dsDataFiltered.Tables.Add(DataTableClon)
19 dsDataFiltered.Tables.Add(dtMessage)
20 Dim newMessageRow As DataRow = dsDataFiltered.Tables("Header").NewRow()
21 newMessageRow("ErrorMessage") = strMessage
22 dsDataFiltered.Tables("Header").Rows.Add(newMessageRow)
23
24 Catch ex As Exception
25 Call ManageError(strGlobalUser, strAppName, strModName, "FilterDataTable", intGlobalMain, Err, strGlobalPathError, ApplicationType.Web)
26 Finally
27 FilterDataTable = dsDataFiltered
28 End Try
29 End Function
Export to a formatted excel file as an attachment (safe mode)
If you want to export a datatable into an excel file keeping each columns place in an excel file and you want also to be asked where you want your excel file to be saved. Then you should use the method I have bellow.
If you are also one of those programmers who had this:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005., then, you should also use this code instead of the one you are currently trying to make work.
I've tried before and it worked fine locally. However, once I deployed it didn't work at all. I tried to find out how to solve that issue and even though I did everything suggested on the net it never worked. May be the reason is because Microsoft doesn't support server side automation at office. You can read more about that here
The method:
Important Considerations:
1.ManageError is a method I use to manage errors, so that you can replace for a simple exit sub or another customized method you use to manage errors.
2. Make sure you will hava an exception type System.Threading.ThreadAbortException in your caller method since that exception will be catched there too.
Apparently the context.response.end automatically runs System.Threading.ThreadAbortException and the only way of avoiding it is catching it. I tried what Microsoft suggest. However, it shows my filter screen page instead of the datatable data.
3. If you don't really need to ask the user where to save your excel file you can simply use the code suggested in this page and forget about that exception.
If you are also one of those programmers who had this:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005., then, you should also use this code instead of the one you are currently trying to make work.
I've tried before and it worked fine locally. However, once I deployed it didn't work at all. I tried to find out how to solve that issue and even though I did everything suggested on the net it never worked. May be the reason is because Microsoft doesn't support server side automation at office. You can read more about that here
The method:
1 Public Sub ExportToSpreadsheet(ByVal tblTable As Data.DataTable, ByVal strName As String)
2 Try
3 Dim context As HttpContext = HttpContext.Current
4 Dim grid As System.Web.UI.WebControls.DataGrid
5 grid = New System.Web.UI.WebControls.DataGrid
6 grid.HeaderStyle.Font.Bold = True
7 grid.DataSource = tblTable
8 grid.DataMember = tblTable.TableName
9 grid.DataBind()
10
11 context.Response.Clear()
12
13 Dim sw As StringWriter
14 sw = New StringWriter()
15
16 Dim hw As HtmlTextWriter
17 hw = New HtmlTextWriter(sw)
18
19 grid.RenderControl(hw)
20 context.Response.Write(sw.ToString)
21 context.Response.AppendHeader("content-disposition", "attachment; filename=" & strName & ".xls")
22 context.Response.ContentType = "application/excel"
23 context.Response.Charset = String.Empty
24 context.Response.Flush()
25 context.Response.End()
26 Catch ex1 As System.Threading.ThreadAbortException
27 Exit Sub
28 Catch ex As Exception
29 Call ManageError("ExportToSpreadsheet", Err)
30 End Try
31
32 End Sub
2 Try
3 Dim context As HttpContext = HttpContext.Current
4 Dim grid As System.Web.UI.WebControls.DataGrid
5 grid = New System.Web.UI.WebControls.DataGrid
6 grid.HeaderStyle.Font.Bold = True
7 grid.DataSource = tblTable
8 grid.DataMember = tblTable.TableName
9 grid.DataBind()
10
11 context.Response.Clear()
12
13 Dim sw As StringWriter
14 sw = New StringWriter()
15
16 Dim hw As HtmlTextWriter
17 hw = New HtmlTextWriter(sw)
18
19 grid.RenderControl(hw)
20 context.Response.Write(sw.ToString)
21 context.Response.AppendHeader("content-disposition", "attachment; filename=" & strName & ".xls")
22 context.Response.ContentType = "application/excel"
23 context.Response.Charset = String.Empty
24 context.Response.Flush()
25 context.Response.End()
26 Catch ex1 As System.Threading.ThreadAbortException
27 Exit Sub
28 Catch ex As Exception
29 Call ManageError("ExportToSpreadsheet", Err)
30 End Try
31
32 End Sub
Important Considerations:
1.ManageError is a method I use to manage errors, so that you can replace for a simple exit sub or another customized method you use to manage errors.
2. Make sure you will hava an exception type System.Threading.ThreadAbortException in your caller method since that exception will be catched there too.
Apparently the context.response.end automatically runs System.Threading.ThreadAbortException and the only way of avoiding it is catching it. I tried what Microsoft suggest. However, it shows my filter screen page instead of the datatable data.
3. If you don't really need to ask the user where to save your excel file you can simply use the code suggested in this page and forget about that exception.
Tuesday, July 13, 2010
ToolTip - RadToolTip
RadTooltip is used as a tooltip to show aditional information that can be formatted in any way you need and, most importantly doesn't disappear after some seconds as the standard tooltip, so it is the user who decides when he/she doesn't want to see it anymore by clicking in a close button.
RadTooltip belongs to the Telerik controls family, so you will need to have it installed.
Quick example - How to use it
1. On the MouseOver event of the txtSUMSGDesc textbox, show a customized tooltip with a textarea inside of it.
The HTML code for the textboxes:
1 <td>
2 <asp:TextBox ID="txtSUMSG" runat="server" CssClass="textbox_disabled2" ReadOnly="False" MaxLength="5" width="33px" ></asp:TextBox>
3 <asp:TextBox ID="txtSUMSGDesc" CssClass="textbox_disabled2" runat="server" Width="180px" AutoPostBack="true"></asp:TextBox>
4 </td>
the HTML code for the RadToolTip
1 <telerik:RadToolTip runat="server" ID="RadToolTip1" Position="TopRight" HideEvent="ManualClose"
2 ShowEvent="OnMouseOver" Width="350px" RelativeTo="Element"
3 TargetControlID="txtSUMSGDesc" OnClientBeforeShow="CheckIfShow">
4 <table width="100%">
5 <tr>
6 <td>
7 <asp:TextBox ID="txtMessageDesc" runat="server" TextMode="MultiLine"
8 Width="300px" CssClass="MessageText"></asp:TextBox>
9 </td>
10 </tr>
11 </table>
12 </telerik:RadToolTip>
The JavaScript functions needed to show the RadToolTip (only when there is information in the textbox)
1 function HideTooltip() {
2 var tooltip = Telerik.Web.UI.RadToolTip.getCurrent();
3 if (tooltip) tooltip.hide();
4 }
5
6 function ShowTooltip() {
7 window.setTimeout(function () {
8 var tooltip = $find("RadToolTip1");
9 //API: show the tooltip
10 tooltip.show();
11 }, 10);
12 }
13
14 function CheckIfShow(sender, args) {
15 var Elem = document.getElementById("<%=txtSUMSGDesc.ClientID%>");
16 //check if summary is visible
17 if (Elem.value == "") {
18 //API: if there are no errors, do not show the tooltip
19 args.set_cancel(true);
20 }
21 }
RadTooltip belongs to the Telerik controls family, so you will need to have it installed.
Quick example - How to use it
1. On the MouseOver event of the txtSUMSGDesc textbox, show a customized tooltip with a textarea inside of it.
The HTML code for the textboxes:
1 <td>
2 <asp:TextBox ID="txtSUMSG" runat="server" CssClass="textbox_disabled2" ReadOnly="False" MaxLength="5" width="33px" ></asp:TextBox>
3 <asp:TextBox ID="txtSUMSGDesc" CssClass="textbox_disabled2" runat="server" Width="180px" AutoPostBack="true"></asp:TextBox>
4 </td>
the HTML code for the RadToolTip
1 <telerik:RadToolTip runat="server" ID="RadToolTip1" Position="TopRight" HideEvent="ManualClose"
2 ShowEvent="OnMouseOver" Width="350px" RelativeTo="Element"
3 TargetControlID="txtSUMSGDesc" OnClientBeforeShow="CheckIfShow">
4 <table width="100%">
5 <tr>
6 <td>
7 <asp:TextBox ID="txtMessageDesc" runat="server" TextMode="MultiLine"
8 Width="300px" CssClass="MessageText"></asp:TextBox>
9 </td>
10 </tr>
11 </table>
12 </telerik:RadToolTip>
The JavaScript functions needed to show the RadToolTip (only when there is information in the textbox)
1 function HideTooltip() {
2 var tooltip = Telerik.Web.UI.RadToolTip.getCurrent();
3 if (tooltip) tooltip.hide();
4 }
5
6 function ShowTooltip() {
7 window.setTimeout(function () {
8 var tooltip = $find("RadToolTip1");
9 //API: show the tooltip
10 tooltip.show();
11 }, 10);
12 }
13
14 function CheckIfShow(sender, args) {
15 var Elem = document.getElementById("<%=txtSUMSGDesc.ClientID%>");
16 //check if summary is visible
17 if (Elem.value == "") {
18 //API: if there are no errors, do not show the tooltip
19 args.set_cancel(true);
20 }
21 }
Labels:
Customized tooltip,
Example RadTooltip,
RadTooltip,
ToolTip
Wednesday, July 7, 2010
Formatting textbox : RadNumericTextBox
If we need to format a textbox, so that we don't need to validate the input and if you can use telerik controls. You should use RadNumericTextBox control.
Before you need something like this in order to validate a number with maximum 4 decimals.
1 <asp:TextBox ID="txtTaxRate" runat="server" CssClass="textbox_num_enabled2" Width="50px" MaxLength="7" text='<%#DataBinder.Eval(Container, "DataItem.TaxRate") %>'></asp:TextBox>
2 <asp:RegularExpressionValidator ID="revTaxRate" runat="server"
3 ErrorMessage="RegularExpressionValidator" CssClass="error2"
4 ControlToValidate="txtTaxRate" ValidationExpression="^\d{0,2}(\.\d{1,4})?$"></asp:RegularExpressionValidator>
5
6
Now, you just need a RadNumeric Textbox like this:
Before you need something like this in order to validate a number with maximum 4 decimals.
1 <asp:TextBox ID="txtTaxRate" runat="server" CssClass="textbox_num_enabled2" Width="50px" MaxLength="7" text='<%#DataBinder.Eval(Container, "DataItem.TaxRate") %>'></asp:TextBox>
2 <asp:RegularExpressionValidator ID="revTaxRate" runat="server"
3 ErrorMessage="RegularExpressionValidator" CssClass="error2"
4 ControlToValidate="txtTaxRate" ValidationExpression="^\d{0,2}(\.\d{1,4})?$"></asp:RegularExpressionValidator>
5
6
Now, you just need a RadNumeric Textbox like this:
1 <telerik:RadNumericTextBox ID="txtTaxRate" runat="server" DataType="System.Int64" MaxLength="9"
2 MaxValue="99.9999" MinValue="0" Skin="" CssClass="textbox_num_enabled2" EnableEmbeddedSkins="False"
3 Width="80px" text='<%#DataBinder.Eval(Container, "DataItem.TaxRate") %>'>
4 <NumberFormat DecimalDigits="4" />
5 </telerik:RadNumericTextBox>
6
7
2 MaxValue="99.9999" MinValue="0" Skin="" CssClass="textbox_num_enabled2" EnableEmbeddedSkins="False"
3 Width="80px" text='<%#DataBinder.Eval(Container, "DataItem.TaxRate") %>'>
4 <NumberFormat DecimalDigits="4" />
5 </telerik:RadNumericTextBox>
6
7
Subscribe to:
Posts (Atom)