Wednesday, April 8, 2015

How to get the Current URL of the page using C#



How to get the Current URL of the page using C#

Below example shows different ways of extracting different parts of URL
EXAMPLE (Sample URL)
http://localhost:1234/WebSite1/Default2.aspx?QueryString1=1&QuerrString2=2
CODE
Response.Write("
 " + HttpContext.Current.Request.Url.Host);
Response.Write("
 " + HttpContext.Current.Request.Url.Authority);
Response.Write("
 " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("
 " + HttpContext.Current.Request.ApplicationPath);
Response.Write("
 " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("
 " + HttpContext.Current.Request.Url.PathAndQuery);
OUTPUT
localhost
localhost:1234
/WebSite1/Default2.aspx
/WebSite1
http://localhost:1234/WebSite/Default2.aspx?QueryString1=1&QuerrString2=2
/WebSite/Default2.aspx?QueryString1=1&QuerrString2=2 

Thursday, December 8, 2011

14 hive and other SharePoint 2010 directories

C:\Inetpub\wwwroot\wss - This directory (or the corresponding directory under the Inetpub root on the server) is used as the default location for IIS Web sites.


C:\ProgramFiles\Microsoft Office Servers\14.0 - This directory is the installation location for SharePoint Server 2010 binaries and data. The directory can be changed during installation.


C:\ProgramFiles\Microsoft Office Servers\14.0\WebServices - This directory is the root directory where SharePoint back-end Web services are hosted, for example, Excel and Search.


C:\ProgramFiles\Microsoft Office Servers\14.0\Data - This directory is the root location where local data is stored, including search indexes.


C:\ProgramFiles\Microsoft Office Servers\14.0\Logs – This directory is the location where the run-time diagnostic logging is generated.


14 hive folders :


Program Files\Common files\Microsoft Shared\Web Server Extensions\14 -
This directory is the installation directory for core SharePoint Server files.


Program Files\Common files\Microsoft Shared\Web Server Extensions\14\ADMISAPI -
This directory contains the soap services for Central Administration. If this directory is altered, remote site creation and other methods exposed in the service will not function correctly.


Program Files\Common files\Microsoft Shared\Web Server Extensions\14\CONFIG -
This directory contains files used to extend IIS Web sites with SharePoint Server. If this directory or its contents are altered, Web application provisioning will not function correctly.


Program Files\Common files\Microsoft Shared\Web Server Extensions\14\LOGS -
This directory contains setup and run-time tracing logs.


Program Files\Common files\Microsoft Shared\Web Server Extensions\Policy -


Program Files\Common files\Microsoft Shared\Web Server Extensions\UserCode -
This directory contains files used to support your sandboxed solutions.


Program Files\Common files\Microsoft Shared\Web Server Extensions\WebClients -
This directory contains files related to the new Client Object Model.


Program Files\Common files\Microsoft Shared\Web Server Extensions\WebServices -
This directory contains new wcf or .svc related files.

Wednesday, November 17, 2010

About Microsoft Dynamics CRM

Microsoft Dynamics CRM:
Microsoft Dynamics CRM made it possible to consolidate and access customer information much more quickly. Microsoft Dynamics CRM works within the MS outlook one of the most popular applications that people use every day.

In Sales, Customer Service, and Marketing makes Microsoft Dynamics CRM an effective way to stay in touch with your customers and drive your business goals.

Microsoft Dynamics CRM is designed to meet the needs of companies of all sizes—from small businesses to large enterprises. Today, Microsoft Dynamics CRM is used by more than 1 million people, including some of the world's largest organizations, in financial services, professional services, manufacturing, and the public sector.

History of MS Dynamics CRM:
- In Dec 2007, MS Dynamics CRM 4.0 launched
- In April 2008, MS Dynamics CRM Online , on an demand service was introduced.
- In Sep 2008, March 2009, and Nov 2009 Service updates for MS Dynamics CRM online were released.
- In July 2009, Free CRM Accelerators were launched with new functionality for analytics, e-Service, Enterprise Search, sales forecasting, sales methodology and support.

Friday, January 29, 2010

Difference between synchronous and asynchronous communication?

Asynchronous:
-asynch comm there is no need to establish a connection before data transmission.
-asynch comm is used in packet swithed networks
-widely used for PC communication and is commonly used for e-mail applications, Internet access, and asynchronous PC-to-PC communications.
-data is transmitted one byte at a time with each byte containing one start bit, eight data bits, and one stop bit, thus yielding a total of ten bits.
- Disadvantage: overhead because every byte sent contains two extra bits (the start and stop bits) and therefore a substantial loss of performance.

Synchronous:
-first connection will be established and the communication
will take place.
-synch comm is used in circut swithed netwoks.
-data is transmitted as frames of large data blocks rather than bulky individual bytes. One advantage of synchronous is that control information is easily inserted at the beginning and end of each block to ensure constant timing, or synchronization.
-Another advantage of synchronous is that it is more efficient than asynchronous. For example, a 56 Kbps dial-up synchronous line can carry 7000 bytes per second (56000/8) compared to a 56 Kbps dial-up asynchronous line which can only carry 5600 bytes per second (56000/10).When transmitting large amounts of information, this translates into a significant increase in speed and performance.

Wednesday, January 6, 2010

Web Part Life Cycle:

- OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part.
- LoadViewState – The view state of the web part is populated over here.
- CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.
- OnLoad
User Generated Event – for e.g. button click on the web part.
- OnPreRender – Here we can change any of the web part properties before the control output is drawn.
- RenderContents – Html Output is generated.
- SaveViewState - View state of the web part is serialized and saved.
- Dispose
- UnLoad.

Tuesday, August 25, 2009

Query for getting the Constraint Information

SELECT f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id

ALTER TABLE Insurance.Contract DROP CONSTRAINT FK_Contract_AccountID

Friday, June 26, 2009

Multi Table Update

select * from A
select * from B

UPDATE A
SET F2 = B.F4
FROM A, B
WHERE A.F1 = B.F3 and A.F2 is null

Thursday, April 16, 2009

Trigger Example.

Sample Trigger

CREATE TABLE dbo.Test (
item varchar(50)
)
GO

CREATE TABLE dbo.Test1 (
item varchar(50)
)
GO

Alter TRIGGER InsertEntry ON dbo.Test AFTER INSERT,UPDATE AS

DECLARE @item int

IF EXISTS(SELECT item FROM inserted)
BEGIN
DECLARE @msg varchar(500)
SET @msg = (SELECT item FROM inserted)
insert into test1 values(@msg)
END
GO

Tuesday, March 31, 2009

Creating Table, Populating the Dates, Retrieving the Weekends in SQL Server 2005

Below Script Create the DateLookup Table:

CREATE TABLE DateLookup
(
DateKey INT PRIMARY KEY,
DateFull DATETIME,
CharacterDate VARCHAR(10),
FullYear CHAR(4),
QuarterNumber TINYINT,
WeekNumber TINYINT,
WeekDayName VARCHAR(10),
MonthDay TINYINT,
MonthName VARCHAR(12),
YearDay SMALLINT,
DateDefinition VARCHAR(30),
WeekDay TINYINT,
MonthNumber TINYINT
)

The below Script Populate the Dates in to the lookup table:

DECLARE @Date DATETIME
SET @Date = '1/1/2009'

WHILE @Date < '1/1/2011'
BEGIN
INSERT INTO DateLookup
(
DateKey, DateFull, FullYear,
QuarterNumber, WeekNumber, WeekDayName,
MonthDay, MonthName, YearDay,
DateDefinition,
CharacterDate,
WeekDay,
MonthNumber
)
SELECT
CONVERT(VARCHAR(8), @Date, 112), @Date, YEAR(@Date),
DATEPART(qq, @Date), DATEPART(ww, @Date), DATENAME(dw, @Date),
DATEPART(dd, @Date), DATENAME(mm, @Date), DATEPART(dy,@Date),
DATENAME(mm, @Date) + ' \' + CAST(DATEPART(dd, @Date) AS CHAR(2)) + ',\'
+ CAST(DATEPART(yy, @Date) AS CHAR(4)),
CONVERT(VARCHAR(10), @Date, 101),
DATEPART(dw, @Date),
DATEPART(mm, @Date)

SET @Date = DATEADD(dd, 1, @Date)
END


To Get the WeekEnds(Saturdays & Sundays) Use the Below Query:

select * from DateLookup where datepart(w,DateFull) in (1) or datepart(w,DateFull) in (7)

Thursday, March 26, 2009

SQL Server: Date Formats

SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD]
Result : 2009/03/05

SELECT CONVERT(VARCHAR(10), GETDATE(), 11) AS [YY/MM/DD]
Result : 09/03/05

SELECT CONVERT(VARCHAR(30), GETDATE(), 131)as Datetime
Result : 9/03/1430 2:05:32:957PM

SELECT CONVERT(VARCHAR(22), GETDATE(), 100)as datetime
Result : Mar 5 2009 2:06PM

SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]
Result :03/05/2009

SELECT CONVERT(VARCHAR(8), GETDATE(), 10) AS [MM-DD-YY]
Result :03-05-09

SELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY]
03-05-2009

SELECT CONVERT(VARCHAR(10), GETDATE(), 7) AS [Mon DD, YY]
Result :Mar 05, 09

SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY]
Result :Mar 05, 2009

SELECT CONVERT(VARCHAR(9), GETDATE(), 6) AS [DD MON YY]
Result :05 Mar 09

SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY]
Result :05 Mar 2009


SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY]
Result :05.03.09

SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY]
Result :05.03.2009

SELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY]
Result :05-03-09


SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY]
Result :05-03-2009

SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY]
Result :05/03/09

SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
Result :05/03/2009

SQL Server 2005 : Split Function

CREATE FUNCTION dbo.Splitter(@strList VARCHAR(8000),@strSeperator VARCHAR(10))
Returns @tblSplit TABLE (splitValue VARCHAR(255))
AS
BEGIN
DECLARE @tmp_FnCommaSplitter TABLE (splitValue VARCHAR(255))
DECLARE @strTmp VARCHAR(5000)
DECLARE @pos INT
DECLARE @lenSeperator INT
SELECT @lenSeperator = LEN(@strSeperator)
SELECT @strTmp = @strList
SELECT @pos = PATINDEX('%'+@strSeperator+'%',@strTmp)
WHILE (@pos <> 0)
BEGIN
IF SUBSTRING(@strTmp,1,@pos-1) <> ''
INSERT @tmp_FnCommaSplitter VALUES (SUBSTRING(@strTmp,1,@pos-1))

SELECT @strTmp = SUBSTRING(@strTmp,@pos+@lenSeperator,5000)
SELECT @pos = PATINDEX('%'+@strSeperator+'%',@strTmp)
END
IF @strTmp <> ''
INSERT @tmp_FnCommaSplitter VALUES (LTRIM(RTRIM(@strTmp)))
INSERT @tblSplit SELECT * FROM @tmp_FnCommaSplitter
RETURN
END

Wednesday, March 18, 2009

SQL Datechecking

DECLARE @datestring varchar(8)
SET @datestring = '12/21/98'
SELECT ISDATE(@datestring)

Monday, January 12, 2009

Procedure to get the record Count instead of using count(*)

sp_spaceused '' for getting the counts.
This will be faster instead of using select count(*)

Wednesday, January 7, 2009

Gridview Manipulations like ADD,DELETE,UPDATE:

Gridview Operations:

http://www.pritambaldota.com/Articles/Article9.aspx

Wednesday, December 31, 2008

Cleaning the Transaction Logs in SQL Server2005

To Back up the transaction log file :
BACKUP LOG TO DISK = ''
Eg.
BACKUP LOG TestDB TO DISK='C:\TestDB1.bak'

To Shrink the transaction log file:

DBCC SHRINKFILE (, ) WITH NO_INFOMSGS

How to clean the transaction Log in SQL Server

use master
go
dump transaction with no_log
go
use
go
DBCC SHRINKFILE (, 100) -- where 100 is the size you may want to shrink it to in MB, change it to your needs
go
-- then you can call to check that all went fine
dbcc checkdb()

(or)

To Truncate the log file:

Backup the database
Detach the database, either by using Enterprise Manager or by executing : *Sp_DetachDB [DBName]*
Delete the transaction log file. (or rename the file, just in case)
Re-attach the database again using: *Sp_AttachDB [DBName]*
When the database is attached, a new transaction log file is created.
To Shrink the log file:

Backup log [DBName] with No_Log
Shrink the database by either:

Using Enterprise manager :- Right click on the database, All tasks, Shrink database, Files, Select log file, OK.

Using T-SQL :- *Dbcc Shrinkfile ([Log_Logical_Name])*

You can find the logical name of the log file by running sp_helpdb or by looking in the properties of the database in Enterprise Manager.

Monday, November 24, 2008

Replace the First Charater in SQL

Query for replacing the first character only.

--select replace(left('Mahesh',1),left('Mahesh',1),'H') + right('Mahesh',len('Mahesh') - 1)

Thursday, October 30, 2008

Generics in .NET 2.0

What Are Generics?
Generics allow you to realize type safety at compile time. They allow you to create a data structure without committing to a specific data type. When the data structure is used, however, the compiler makes sure that the types used with it are consistent for type safety. Generics provide type safety, but without any loss of performance or code bloat. While they are similar to templates in C++ in this regard, they are very different in their implementation.

The short answer is this: "without generics, it is very difficult to create type-safe collections".

Creating Our First Generic Type:

public class Col {
T t;
public T Val{get{return t;}set{t=value;}}
}


public class ColMain {
public static void Main() {
//create a string version of our generic class
Col mystring = new Col();
//set the value
mystring.Val = "hello";

//output that value
System.Console.WriteLine(mystring.Val);
//output the value's type
System.Console.WriteLine(mystring.Val.GetType());

//create another instance of our generic class, using a different type
Col myint = new Col();
//load the value
myint.Val = 5;
//output the value
System.Console.WriteLine(myint.Val);
//output the value's type
System.Console.WriteLine(myint.Val.GetType());

}
}


When we compile the two classes above and then run them, we will see the following output:

hello
System.String
5
System.Int32

Generic Collections:

User.cs


namespace Rob {
public class User {
protected string name;
protected int age;
public string Name{get{return name;}set{name=value;}}
public int Age{get{return age;}set{age=value;}}
}
}


Main.cs

public class M {
public static void Main(string[] args) {
System.Collections.Generic.List users = new System.Collections.Generic.List();
for(int x=0;x<5;x++) {
Rob.User user = new Rob.User();
user.Name="Rob" + x;
user.Age=x;
users.Add(user);
}

foreach(Rob.User user in users) {
System.Console.WriteLine(System.String.Format("{0}:{1}", user.Name, user.Age));
}
System.Console.WriteLine("press enter");
System.Console.ReadLine();

for(int x=0;x System.Console.WriteLine(System.String.Format("{0}:{1}", users[x].Name, users[x].Age));
}

}
}


Output

Rob0:0
Rob1:1
Rob2:2
Rob3:3
Rob4:4
press enter

Rob0:0
Rob1:1
Rob2:2
Rob3:3
Rob4:4