1- Go to the code-behind of the .aspx page you wish to create the browser cookie from. I will show 2 approaches on creating such a cookie.
2- Method 1:
// A cookie called "userInfo" is dynamically created and the key "userName" is assigned the value "patrick".
Response.Cookies["userInfo"]["userName"] = "patrick";
// A new key called "lastVisit" is added to the collection of values in the cookie and assigned the current datetime value.
Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString();
// The expiration value of the cookie is set to 1 day in the future from the current date.
Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1);
3- Method 2:
HttpCookie aCookie = new HttpCookie("userInfo");
// The key "userName" is added to the cookie and assigned the value "patrick" as the above example.
aCookie.Values["userName"] = "patrick";
// The key "lastVisit" is added to the cookie and assigned the current datetime value.
aCookie.Values["lastVisit"] = DateTime.Now.ToString();
// The expiration date of the cookie is set to 1 day in the future from the current date.
aCookie.Expires = DateTime.Now.AddDays(1);
// Add the cookie to the browser cookie collection.
Response.Cookies.Add(aCookie);
C# etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
C# etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
CSharp: How to fix following C# error in Visual Studio: Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'
Error:
Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'
Cause:
string variable = Table[0][1].ToString();
Solution:
DataTable Table;string variable = Table.Rows[index][column-index].ToString();
Example:
DataTable Table;
string variable = Table.Rows[0][1].ToString();
The above error happens when you try to index the datatable without first accessing the "Rows" property. You must first access the "Rows" property and then provide the index.
Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'
Cause:
string variable = Table[0][1].ToString();
Solution:
DataTable Table;string variable = Table.Rows[index][column-index].ToString();
Example:
DataTable Table;
string variable = Table.Rows[0][1].ToString();
The above error happens when you try to index the datatable without first accessing the "Rows" property. You must first access the "Rows" property and then provide the index.
How to read the first sheet in Excel with C#
string AppPath=Request.ServerVariables["APPL_PHYSICAL_PATH"]+"Tahsilat/";
OleDbConnection m_ConnectionToExcelBook;
OleDbDataAdapter m_AdapterForExcelBook;
m_ConnectionToExcelBook = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+AppPath+"deneme.xls;Extended Properties=Excel 8.0;");
bool ErrorExist=false;
try
{
m_ConnectionToExcelBook.Open();
DataTable dtExcelSchema = m_ConnectionToExcelBook.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
// select first sheetname
string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
DataTable DataObject = new DataTable();
OleDbCommand selectCommand = new OleDbCommand("select * from [" + sheetName + "]");
selectCommand.Connection = m_ConnectionToExcelBook;
m_AdapterForExcelBook = new OleDbDataAdapter();
m_AdapterForExcelBook.SelectCommand = selectCommand;
m_AdapterForExcelBook.Fill(DataObject);
if (DataObject.Rows.Count > 0)
{
.......
.......
}
Adding TextBox Values using Javascript in C#
The following code sample shows how to add the textbox values using javascript.
The keyup event of the textbox is used. Three textboxes is use , the functionality is to add the first and second textboxes and total in third textbox.
Step 1-The Javascript Function follows :
function KeyUpEvent(){
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
var txt3 = document.getElementById("txt3");
if ((txt1.value != "") && (txt2.value != ""))
{
txt3.value = parseInt(txt1.value) + parseInt(txt2.value);
}
}
Step 2-Design
Step 3-To add attributes to the textbox at code behind use this example:
txt1.Attributes.Add("onKeyUp", "javascript:KeyUpEvent();");
txt2.Attributes.Add("onKeyUp", "javascript:KeyUpEvent();");
Arrays in C#
Arrays
Arrays are a special type, built into C#, that holds a group of other types. Arrays are a useful construct for organizing data. They provide matrix support and, even further, multidimensional support. As a collection, an array allows going beyond simple storage of data and provides fundamental discovery and manipulation of that data. Array methods are discussed in the next chapter. This chapter shows declaration and instantiation of single-dimension, multidimension, and jagged arrays.
Single-Dimension Arrays
Single-dimension arrays provide the capability to store and manipulate a list of items. Every element is of the same type. This is how such an array should be declared:
Type[] Array-Identifier [initializer] ;
The array identifier is any valid identifier. It should be meaningful for the purpose of the array. The optional initializer allocates memory for the array.
TIP
Once a C# array has been initialized, it can't change its size. If dynamic resizing of an array is needed, use one of the collection classes.
Here are some examples of single-dimensional array declarations:
// uninitialized declaration
MyClass[] myArray;
byte[] inputBuffer = new byte[2048];
// creates an array of 3 strings
string[] countStrings = { "one", "two", "three" };
Arrays may be declared with no initialization. Remember, an array must be initialized before it's used. It may be initialized with an integer type value inside the brackets of the initializer, as the following example shows:
// creates an array of 3 strings
string[] countStrings = new string[3] { "one ", " two", " three" };
Another way to initialize an array is by leaving the space in the brackets of the initializer blank and then following the initializer brackets with an initializer list in braces. The array initializer list is a comma-separated list of values of the array type. The size of the array becomes the number of elements in the initializer list. If an integer value is added to the initializer brackets and there is an initializer list in the same array initializer, make sure that the integer value in the initializer brackets is greater than or equal to the number of elements in the initializer list. Take a look at this code sample:
// error
string[] countStrings = new string[3] { "one", "two", "three", "four" };
The initializer in this code fails with an error because the allocated size of the countStrings array is only 3, but the number of strings in the list is four. The number of strings in the list can't exceed the allocated size.
TIP
Don't specify a size when using an initializer list on an array. Later, it will be easier to add an item to the list and avoid the mistake of not incrementing the number.
Dimensional Arrays
Multidimensional arrays are similar in declaration and initialization to single-dimensional arrays, with a few exceptions. For every new dimension included, add a comma to brackets of the array declaration. During initialization, add an integer value to each of the dimensions specified in the declaration. Here are a couple examples:
long [ , ] determinant = new long[4, 4];
int [ , , ] stateSpace = new int[2, 5, 4];
bool [ , ] exclusiveOr
= new bool[2, 2] { {false, true}, {true, false} };
Remember, the integer values in the initializer brackets are optional when including an initializer list.
Jagged Arrays
Jagged arrays allow creation of multidimensional arrays without the requirement of making every element of every dimension the same size. If an application has data that doesn't cover the entire range of possible values, this may be an option. It may also open the opportunity to save memory space. Here are some examples:
decimal[][] monthlyVariations = new decimal[12][];
monthlyVariations[(int)Months.Jan] = new decimal[31];
monthlyVariations[(int)Months.Feb] = new decimal[28];
.
.
.
monthlyVariations[(int)Months.Dec] = new decimal[31];
Arrays are a special type, built into C#, that holds a group of other types. Arrays are a useful construct for organizing data. They provide matrix support and, even further, multidimensional support. As a collection, an array allows going beyond simple storage of data and provides fundamental discovery and manipulation of that data. Array methods are discussed in the next chapter. This chapter shows declaration and instantiation of single-dimension, multidimension, and jagged arrays.
Single-Dimension Arrays
Single-dimension arrays provide the capability to store and manipulate a list of items. Every element is of the same type. This is how such an array should be declared:
Type[] Array-Identifier [initializer] ;
The array identifier is any valid identifier. It should be meaningful for the purpose of the array. The optional initializer allocates memory for the array.
TIP
Once a C# array has been initialized, it can't change its size. If dynamic resizing of an array is needed, use one of the collection classes.
Here are some examples of single-dimensional array declarations:
// uninitialized declaration
MyClass[] myArray;
byte[] inputBuffer = new byte[2048];
// creates an array of 3 strings
string[] countStrings = { "one", "two", "three" };
Arrays may be declared with no initialization. Remember, an array must be initialized before it's used. It may be initialized with an integer type value inside the brackets of the initializer, as the following example shows:
// creates an array of 3 strings
string[] countStrings = new string[3] { "one ", " two", " three" };
Another way to initialize an array is by leaving the space in the brackets of the initializer blank and then following the initializer brackets with an initializer list in braces. The array initializer list is a comma-separated list of values of the array type. The size of the array becomes the number of elements in the initializer list. If an integer value is added to the initializer brackets and there is an initializer list in the same array initializer, make sure that the integer value in the initializer brackets is greater than or equal to the number of elements in the initializer list. Take a look at this code sample:
// error
string[] countStrings = new string[3] { "one", "two", "three", "four" };
The initializer in this code fails with an error because the allocated size of the countStrings array is only 3, but the number of strings in the list is four. The number of strings in the list can't exceed the allocated size.
TIP
Don't specify a size when using an initializer list on an array. Later, it will be easier to add an item to the list and avoid the mistake of not incrementing the number.
Dimensional Arrays
Multidimensional arrays are similar in declaration and initialization to single-dimensional arrays, with a few exceptions. For every new dimension included, add a comma to brackets of the array declaration. During initialization, add an integer value to each of the dimensions specified in the declaration. Here are a couple examples:
long [ , ] determinant = new long[4, 4];
int [ , , ] stateSpace = new int[2, 5, 4];
bool [ , ] exclusiveOr
= new bool[2, 2] { {false, true}, {true, false} };
Remember, the integer values in the initializer brackets are optional when including an initializer list.
Jagged Arrays
Jagged arrays allow creation of multidimensional arrays without the requirement of making every element of every dimension the same size. If an application has data that doesn't cover the entire range of possible values, this may be an option. It may also open the opportunity to save memory space. Here are some examples:
decimal[][] monthlyVariations = new decimal[12][];
monthlyVariations[(int)Months.Jan] = new decimal[31];
monthlyVariations[(int)Months.Feb] = new decimal[28];
.
.
.
monthlyVariations[(int)Months.Dec] = new decimal[31];
Kaydol:
Kayıtlar (Atom)
BlackListIP control on Serenity platform (.NET Core)
In the Serenity platform, if you want to block IPs that belong to people you do not want to come from outside in the .net core web project,...
-
In the Serenity platform, if you want to block IPs that belong to people you do not want to come from outside in the .net core web project,...
-
TABLO ADI AÇIKLAMA L_PERSONEL Çalışma Alanı Tanımları L_SYSLOG Kullanıcı Kaydı İzleme L_L...
-
Microsoft OLE DB Provider for SQL Server : Cannot create a row of size 8100 which is greater than the allowable maximum of 8060. (80040E14) ...