The DateTime Ticks property simply returns a long that represents the amount of ticks (100-nanosecond interval) that have passed since january 1, 0001 12:00:00.
using System;
class Program
{
static void Main()
{
DateTime variable = DateTime.Now;
long ticks = variable.Ticks;
Console.WriteLine(ticks);
Console.Read();
}
}
output:633117518171562500
Convery Ticks Back to DateTime
Now that we have converted a DateTime object to a Ticks now we have to learn how to convert is back to a DateTime value.
using System;
class Program
{
static void Main()
{
long ticks = 633117518171562500;
DateTime date = new DateTime(ticks);
Console.WriteLine(date.ToString());
Console.Read();
}
}
Output: 4/9/2007 9:43:37 PM
Sunday, 17 July 2011
Thursday, 14 July 2011
Show a word document content in asp.net page
using Microsoft.Office.Interop.Word;
//fuction
private void readFileContent(string path)
{
ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
string sFileText = doc.Content.Text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
Response.Write(sFileText);
}
Thursday, 16 June 2011
Jquery validate for gridview inner control(Lable,Textbox) on button click Event
$('#btnSubmit').click(function () {
var isValid = true;
$("table[id$='gvPurchase']").find("span.validate").each(function () {
//span use for lable control and validate is class of the control
// <asp:Label ID="Label2" runat="server" class="validate" Text="0"></asp:Label>
if ($(this).html() == "") {
$("#gvValidate").html("*Rate and quantity not be null");
isValid = false;
}
if (parseInt($(this).html()) <= 0) {
$("#gvValidate").html("*Rate and quantity must be grater then zero");
isValid = false;
}
});
Friday, 27 May 2011
Change image size in asp.net with C#.
System.Drawing.Image image = System.Drawing.Image.FromFile(url+"/"+filename);
int srcWidth = image.Width;
int thumbWidth;
int srcHeight = image.Height;
int thumbHeight = 440;
Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
System.Drawing.Rectangle rectDestination = new
System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);
string newfilename = filename.Substring(0, filename.LastIndexOf('.'))+reference;
string fileExt=filename.Substring(filename.LastIndexOf('.'));
bmp.Save(url + "\\" + newfilename + fileExt);
bmp.Dispose();
image.Dispose();
Thursday, 19 May 2011
What is httpHandler & httpModule?
httpHandler – Extenstion Based Preprocessor :
ASP.NET HTTP handler is the process that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
httpModule – Event based Preprocessor :
An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.
When to use HTTP handlers:
“Modules are called before and after the handler executes. Modules enable developers to intercept, participate in, or modify each individual request. Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET Framework to process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one handler is used to process a request”.
ASP.NET HTTP handler is the process that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
httpModule – Event based Preprocessor :
An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.
When to use HTTP handlers:
- RSS feeds: To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. You can then bind a file name extension such as .rss to the custom handler. When users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.
- Image server: If you want a Web application to serve images in a variety of sizes, you can write a custom handler to resize images and then send them to the user as the handler’s response.
- Security: Because you can examine incoming requests, an HTTP module can perform custom authentication or other security checks before the requested page, XML Web service, or handler is called. In Internet Information Services (IIS) 7.0 running in Integrated mode, you can extend forms authentication to all content types in an application.
- Statistics and logging: Because HTTP modules are called on every request, you can gather request statistics and log information in a centralized module, instead of in individual pages.
- Custom headers or footers: Because you can modify the outgoing response, you can insert content such as custom header information into every page or XML Web service response.
- The IHttpHandler and IHttpModule interfaces are the starting point for developing handlers and modules.
The IHttpAsyncHandler interface is the starting point for developing asynchronous handlers. - Custom handler and module source code can be put in the App_Code folder of an application, or it can be compiled and put in the Bin folder of an application.
- Handlers and modules developed for use in IIS 6.0 can be used in IIS 7.0 with little or no change.
- Modules can subscribe to a variety of request-pipeline notifications. Modules can receive notification of events of the HttpApplication object.
- ASP.NET page handler (*.aspx): The default HTTP handler for all ASP.NET pages.
- Web service handler (*.asmx): The default HTTP handler for Web service pages created as .asmx files in ASP.NET.
- Generic Web handler (*.ashx): The default HTTP handler for all Web handlers that do not have a UI and that include the @ WebHandler directive.
- Trace handler (trace.axd): A handler that displays current page trace information.
“Modules are called before and after the handler executes. Modules enable developers to intercept, participate in, or modify each individual request. Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET Framework to process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one handler is used to process a request”.
Tuesday, 29 March 2011
Difference between @@IDENTITY and SCOPE_IDENTITY()
@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions because they all return the last value inserted into the IDENTITY column of a table.It took me a minute to find a good example to illustrate the difference between the two, but with a trigger I created the following example:
@@IDENTITY and SCOPE_IDENTITY return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
USE TempDB
GO
CREATE TABLE tst
( a int identity(1,1), s varchar(10))
GO
CREATE TABLE tst2
( a int identity(1000,1), s varchar(10))
GO
CREATE TRIGGER dbo.trgTst
ON tst
AFTER INSERT
AS INSERT tst2 SELECT inserted.s FROM inserted
GO
INSERT tst VALUES('a')
SELECT
@@IDENTITY AS [@@IDENTITY],
SCOPE_IDENTITY() AS [SCOPE_IDENTITY()]
GO
DROP TABLE tst2
DROP TABLE tst
SCOPE_IDENTITY() will give you the value of tst.$IDENTITY, ignoring the identity value that is generated for table tst2 with the trigger after the insert into tst. @@IDENTITY will give you that value from tst2.$IDENTITY.
So the function we actually need in our case is not @@IDENTITY but SCOPE_IDENTITY().
Subscribe to:
Posts (Atom)
Table Partitioning in SQL Server
Table Partitioning in SQL Server – Step by Step Partitioning in SQL Server task is divided into four steps: Create a File Group Add Files ...
-
Introduction In Web Programming, the refresh click or postback is the big problem which generally developers face. So in order to avoid...
-
Global .asax file- <%@ Application Language = "C#" %> <script runat= "server" > void...
-
SELECT T.name AS [TABLE NAME], I.rows AS [ROWCOUNT] FROM sys.tables AS T INNER JOIN sys.sysindexes AS I ...