To open PDF i have mentioned two methods as below,
1. Process[] processes = System.Diagnostics.Process.GetProcessesByName("AcroRd32");
foreach (Process p in processes)
{
p.Kill();
p.Refresh();
}
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start(strPDFPath);
2. System.Net.WebClient client = new System.Net.WebClient();
Byte[] buffer = client.DownloadData(strPDFPath);
Session["BUFFER"] = buffer;
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "PDF", "window.open('../pdf.aspx','_blank');", true);
In "pdf.aspx.cs" file use this code
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["BUFFER"] != null)
{
byte[] buffer = (Byte[])Session["BUFFER"];
if (buffer != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.AddHeader("Content-Type", "application/pdf");
Response.BinaryWrite(buffer);
Response.End();
}
}
}
catch (Exception)
{
}
}
Sunday, January 31, 2010
Setting permission to the folder programmatically using C#.Net
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
string dirpath = "C:\\Web\\DirPath";
DirectoryInfo dirinfo = new DirectoryInfo(dirpath);
string users = @"NETWORK SERVICE"; //@"ASPNET" // @"EVERYONE"
if (dirinfo.Exists)
{
DirectorySecurity dirsec = dirinfo.GetAccessControl();
FileSystemAccessRule fsar = new FileSystemAccessRule(new NTAccount(users), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
dirsec.AddAccessRule(fsar);
dirinfo.SetAccessControl(dirsec);
}
using System.Security.AccessControl;
using System.Security.Principal;
string dirpath = "C:\\Web\\DirPath";
DirectoryInfo dirinfo = new DirectoryInfo(dirpath);
string users = @"NETWORK SERVICE"; //@"ASPNET" // @"EVERYONE"
if (dirinfo.Exists)
{
DirectorySecurity dirsec = dirinfo.GetAccessControl();
FileSystemAccessRule fsar = new FileSystemAccessRule(new NTAccount(users), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
dirsec.AddAccessRule(fsar);
dirinfo.SetAccessControl(dirsec);
}
AutoComplete Extender Without WebService
1. Creating a Common class file to GetAutoCompleteList items
public string[] GetAutoCompleteList(string strPrefix)
{
DataTable dt = new DataTable();
//Create [SP/Query] to Get the Items from Database
//Assume "dt" has got Records from Database
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["COLNAME"].ToString(), i);
i++;
}
return items;
}
2. This Web Method can be created within the "page.aspx.cs" file.
[WebMethod]
public static string[] GetAutoCompleteItems(string prefixText)
{
ClsFile objFile = new ClsFile();
return objFile.GetAutoCompleteList(prefixText);
}
3. This following code is to be used in the "page.aspx" file
(Start Tag)asp:TextBox ID="txtListItems" AutoComplete="off" style="text-transform:capitalize" ToolTip="Enter List Item Prefix" Width="130px" runat="server" OnTextChanged=" txtListItems _TextChanged" AutoPostBack="True"(End Tag)
(Start Tag)cc1:AutoCompleteExtender ID=" txtListItems _AutoCompleteExtender" runat="server" ServiceMethod=" GetAutoCompleteItems " DelimiterCharacters=";, :" Enabled="True" TargetControlID=" txtListItems " MinimumPrefixLength="1" CompletionInterval="10" FirstRowSelected="true" EnableCaching="true" CompletionSetCount="12" (End Tag)
public string[] GetAutoCompleteList(string strPrefix)
{
DataTable dt = new DataTable();
//Create [SP/Query] to Get the Items from Database
//Assume "dt" has got Records from Database
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["COLNAME"].ToString(), i);
i++;
}
return items;
}
2. This Web Method can be created within the "page.aspx.cs" file.
[WebMethod]
public static string[] GetAutoCompleteItems(string prefixText)
{
ClsFile objFile = new ClsFile();
return objFile.GetAutoCompleteList(prefixText);
}
3. This following code is to be used in the "page.aspx" file
(Start Tag)asp:TextBox ID="txtListItems" AutoComplete="off" style="text-transform:capitalize" ToolTip="Enter List Item Prefix" Width="130px" runat="server" OnTextChanged=" txtListItems _TextChanged" AutoPostBack="True"(End Tag)
(Start Tag)cc1:AutoCompleteExtender ID=" txtListItems _AutoCompleteExtender" runat="server" ServiceMethod=" GetAutoCompleteItems " DelimiterCharacters=";, :" Enabled="True" TargetControlID=" txtListItems " MinimumPrefixLength="1" CompletionInterval="10" FirstRowSelected="true" EnableCaching="true" CompletionSetCount="12" (End Tag)
Monday, January 25, 2010
SQL convert number to text
CREATE FUNCTION fnMoneyToEnglish(@Money AS money)
RETURNS VARCHAR(1024)
AS
BEGIN
DECLARE @Number as BIGINT
SET @Number = FLOOR(@Money)
DECLARE @Below20 TABLE (ID int identity(0,1), Word varchar(32))
DECLARE @Below100 TABLE (ID int identity(2,1), Word varchar(32))
INSERT @Below20 (Word) VALUES
( 'Zero'), ('One'),( 'Two' ), ( 'Three'),
( 'Four' ), ( 'Five' ), ( 'Six' ), ( 'Seven' ),
( 'Eight'), ( 'Nine'), ( 'Ten'), ( 'Eleven' ),
( 'Twelve' ), ( 'Thirteen' ), ( 'Fourteen'),
( 'Fifteen' ), ('Sixteen' ), ( 'Seventeen'),
('Eighteen' ), ( 'Nineteen' )
INSERT @Below100 VALUES ('Twenty'), ('Thirty'),('Forty'), ('Fifty'),
('Sixty'), ('Seventy'), ('Eighty'), ('Ninety')
DECLARE @English varchar(1024) =
(
SELECT Case
WHEN @Number = 0 THEN ''
WHEN @Number BETWEEN 1 AND 19
THEN (SELECT Word FROM @Below20 WHERE ID=@Number)
WHEN @Number BETWEEN 20 AND 99
-- SQL Server recursive function
THEN (SELECT Word FROM @Below100 WHERE ID=@Number/10)+ '-' +
dbo.fnMoneyToEnglish( @Number % 10)
WHEN @Number BETWEEN 100 AND 999
THEN (dbo.fnMoneyToEnglish( @Number / 100))+' Hundred '+
dbo.fnMoneyToEnglish( @Number % 100)
WHEN @Number BETWEEN 1000 AND 999999
THEN (dbo.fnMoneyToEnglish( @Number / 1000))+' Thousand '+
dbo.fnMoneyToEnglish( @Number % 1000)
WHEN @Number BETWEEN 1000000 AND 999999999
THEN (dbo.fnMoneyToEnglish( @Number / 1000000))+' Million '+
dbo.fnMoneyToEnglish( @Number % 1000000)
ELSE ' INVALID INPUT' END
)
SELECT @English = RTRIM(@English)
SELECT @English = RTRIM(LEFT(@English,len(@English)-1))
WHERE RIGHT(@English,1)='-'
IF @@NestLevel = 1
BEGIN
SELECT @English = @English+' Dollars and '
SELECT @English = @English+
convert(varchar,convert(int,100*(@Money - @Number))) +' Cents'
END
RETURN (@English)
END
GO
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 67)
-- Sixty-Seven Dollars and 0 Cents
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 947.54)
-- Nine Hundred Forty-Seven Dollars and 54 Cents
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 1266.04)
-- One Thousand Two Hundred Sixty-Six Dollars and 4 Cents
RETURNS VARCHAR(1024)
AS
BEGIN
DECLARE @Number as BIGINT
SET @Number = FLOOR(@Money)
DECLARE @Below20 TABLE (ID int identity(0,1), Word varchar(32))
DECLARE @Below100 TABLE (ID int identity(2,1), Word varchar(32))
INSERT @Below20 (Word) VALUES
( 'Zero'), ('One'),( 'Two' ), ( 'Three'),
( 'Four' ), ( 'Five' ), ( 'Six' ), ( 'Seven' ),
( 'Eight'), ( 'Nine'), ( 'Ten'), ( 'Eleven' ),
( 'Twelve' ), ( 'Thirteen' ), ( 'Fourteen'),
( 'Fifteen' ), ('Sixteen' ), ( 'Seventeen'),
('Eighteen' ), ( 'Nineteen' )
INSERT @Below100 VALUES ('Twenty'), ('Thirty'),('Forty'), ('Fifty'),
('Sixty'), ('Seventy'), ('Eighty'), ('Ninety')
DECLARE @English varchar(1024) =
(
SELECT Case
WHEN @Number = 0 THEN ''
WHEN @Number BETWEEN 1 AND 19
THEN (SELECT Word FROM @Below20 WHERE ID=@Number)
WHEN @Number BETWEEN 20 AND 99
-- SQL Server recursive function
THEN (SELECT Word FROM @Below100 WHERE ID=@Number/10)+ '-' +
dbo.fnMoneyToEnglish( @Number % 10)
WHEN @Number BETWEEN 100 AND 999
THEN (dbo.fnMoneyToEnglish( @Number / 100))+' Hundred '+
dbo.fnMoneyToEnglish( @Number % 100)
WHEN @Number BETWEEN 1000 AND 999999
THEN (dbo.fnMoneyToEnglish( @Number / 1000))+' Thousand '+
dbo.fnMoneyToEnglish( @Number % 1000)
WHEN @Number BETWEEN 1000000 AND 999999999
THEN (dbo.fnMoneyToEnglish( @Number / 1000000))+' Million '+
dbo.fnMoneyToEnglish( @Number % 1000000)
ELSE ' INVALID INPUT' END
)
SELECT @English = RTRIM(@English)
SELECT @English = RTRIM(LEFT(@English,len(@English)-1))
WHERE RIGHT(@English,1)='-'
IF @@NestLevel = 1
BEGIN
SELECT @English = @English+' Dollars and '
SELECT @English = @English+
convert(varchar,convert(int,100*(@Money - @Number))) +' Cents'
END
RETURN (@English)
END
GO
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 67)
-- Sixty-Seven Dollars and 0 Cents
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 947.54)
-- Nine Hundred Forty-Seven Dollars and 54 Cents
SELECT NumberInEnglish=dbo.fnMoneyToEnglish ( 1266.04)
-- One Thousand Two Hundred Sixty-Six Dollars and 4 Cents
Subscribe to:
Posts (Atom)