TEST

Blog Pages

Thursday, May 26, 2011

ASP.net Validator "Get And Set The Background Color of ControlToValidate if it is enable "

 function ChangeValidators() {
            var myarray = new Array(1);
            var myarray2 = new Array(1);
//page validator array and get the validator id with controltovalidate id
             for (var i = 0; i < Page_Validators.length; i++) {
                var val = Page_Validators[i];       //validator object
                var valdtr = Page_Validators[i].id;    //validator id
                var ctrl = document.getElementById(val.controltovalidate); //get contorltovalidate By ID
//check controlToValidate have a value               
                if (ctrl != null && ctrl.style != null) {
                    if (!val.isvalid) {
                        myarray[i]= ctrl;  //add controltoValidate into array list
                        myarray2[i] = valdtr;
                    }
                    else
                        ctrl.style.backgroundColor = 'White';
                }
            }
//this loop is use to change the Background Color of Validator
            for (var i = 0; i < myarray.length; i++) {
                var ctrl = myarray[i];
               if( ctrl!=undefined)
                   ctrl.style.background = 'lightGoldenRodYellow';
               var validtrID = myarray2[i];     
            if (validtrID != undefined) {       
                 var valdtr = document.getElementById(validtrID);
                ValidatorEnable(valdtr, true);      
                valdtr.isvalid = false;
                ValidatorUpdateDisplay(valdtr);
            }
              
            }
        }


asp:button id=btnSave onclientclick=javascript:fnOnUpdateValidators(); runat=server text=Validate


Wednesday, May 11, 2011

Google Calender





Thursday, October 14, 2010

Using Webpartzone,WebPartmanager



First of all you should download the Asp.Net future July 2007 Plug-in to use Web-part
"http://www.microsoft.com/downloads/en/details.aspx?FamilyId=A5189BCB-EF81-4C12-9733-E294D13A58E6&displaylang=en"
and install it. Now run the Visual Studio 2008-2010.
Create a new WebSite project and open default.aspx page.
In 2008 Toolbox you can see Asp.net Future which is automatically added but in 2010 you should right click on the Toolbox and select "Choose Items" and then click the "Browse" and go to the following location " C:\Program Files\Microsoft ASP.NET\ASP.NET Futures July 2007\v1.3.61025\3.5" and select all components and then press OK.
Now you can see the Asp.Net Future tab in Toolbox.
now drag the WebPartManager and then WebPartZone but don't forget the "scriptmanager"


in the below example i am using the ASP.net Member Provider for login and register the member and maintain its session and its webpart setting. So go to the
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe
if you are using VS2010 other find aspnet_regsql in the above folder.
and run it and


See the below example
Design Code








CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Web.Preview.UI.Controls.WebParts;

namespace AspWebPart
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (WebPartManager1.Personalization.Scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User)
{
if (WebPartManager1.Personalization.CanEnterSharedScope)
{
WebPartManager1.Personalization.ToggleScope();

}
}

}



protected void btnDisplay_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}

protected void btnEdit_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;
}

protected void btnDesign_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
}

protected void btnCatalog_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}


}
}



Web.Config File





Thursday, September 16, 2010

How to extract pages from a PDF document

One of the great things about being a programmer is that when you need software that you don’t have, you can usually write a small utility application to do what you need without having to purchase the software.
If you own Adobe Acrobat ($299 USD) or FoxIt Editor ($99.00 USD), then you can just right click and extract pages from an existing PDF to create a new PDF document. However, if you don’t want to shell out the money for it, then you can always write your own code to perform the same task.
I used iTextSharp in a previous application to provide a capability of exporting documents to PDF, so I was familiar with the iTextSharp project. In that application, I was able to create PDF documents for various paper sizes ranging from 8 1/2 x 11 and legal sizes to large format plotter pages sizes such as D and E-size pages. The library worked great and produce near perfect PDF documents of our displays.
Today, I needed to extract a couple pages from a PDF file to create a new PDF document and I realized that I didn’t have a PDF editor… So I went out and downloaded iTextSharp library and wrote a small program to do the work for me.
I’ll just brush over the basic program setup.
I used a C# console application as my starting point
There are 4 command line arguments (input file, output file, starting page, and ending page)
Validate that the input file exists
Validate that the input file is a PDF document
Validate that the starting and ending page numbers are valid
Add two using directives for iTextSharp.text and iTextSharp.text.pdf
Okay, here’s the primary method of the application. You can see the four input parameters and the code comments should provide enough information to walk you through the steps.private static void ExtractPages(string inputFile, string outputFile,
int start, int end)
{
// get input document
PdfReader inputPdf = new PdfReader(inputFile);
// retrieve the total number of pages
int pageCount = inputPdf.NumberOfPages;
if (end <> pageCount)
{
end = pageCount;
}
// load the input document
Document inputDoc =
new Document(inputPdf.GetPageSizeWithRotation(1));
// create the filestream
using (FileStream fs = new FileStream(outputFile, FileMode.Create))
{
// create the output writer
PdfWriter outputWriter = PdfWriter.GetInstance(inputDoc, fs);
inputDoc.Open();
PdfContentByte cb1 = outputWriter.DirectContent;
// copy pages from input to output document
for (int i = start; i <= end; i++) { inputDoc.SetPageSize(inputPdf.GetPageSizeWithRotation(i)); inputDoc.NewPage(); PdfImportedPage page = outputWriter.GetImportedPage(inputPdf, i); int rotation = inputPdf.GetPageRotation(i); if (rotation == 90 rotation == 270) { cb1.AddTemplate(page, 0, -1f, 1f, 0, 0, inputPdf.GetPageSizeWithRotation(i).Height); } else { cb1.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); } } inputDoc.Close(); } }


How to merge pages from a PDF document

This article will use the same library, iTextSharp, to merge pages from one PDF document to create a second PDF document.
For this utility, imagine having a PDF document with pages that are 8 1/2″ x 11″ and you want to combine 2 pages into one larger page. The resulting output document would be 17″ x 11″ and show two pages from the input document on one page on the output document.
I’ll just brush over the basic program setup.
I used a C# console application as my starting point
There are 2 command line arguments (input file and output file)
Validate that the input file exists
Validate that the input file is a PDF document
Add two using directives for iTextSharp.text and iTextSharp.text.pdf
Here’s the primary method of the application. The code comments should provide enough information to walk you through the steps.private static void MergePages(string inputFile, string outputFile)
{
// get input document
PdfReader inputPdfReader = new PdfReader(inputFile);
// load the input document
Document inputPdfDoc =
new Document(inputPdfReader.GetPageSizeWithRotation(1));
// create the filestream
using (FileStream fs = new FileStream(outputFile, FileMode.Create))
{
// create the output writer
PdfWriter outputWriter =
PdfWriter.GetInstance(inputPdfDoc, fs);
inputPdfDoc.Open();
PdfContentByte pdfCb = outputWriter.DirectContent;
// loop through each page in input pdf reader
for (int i = 1; i <= inputPdfReader.NumberOfPages; i++) { float leftOffset = 1f; // if even page (0,2,4,...) if (i % 2 == 1) { Rectangle inputPageSize = inputPdfReader.GetPageSizeWithRotation(i); Rectangle outputPageSize = new Rectangle(0, 0, inputPageSize.Width * 2, inputPageSize.Height); //add new page that is x2 width inputPdfDoc.SetPageSize(outputPageSize); inputPdfDoc.NewPage(); // draw vertical line pdfCb.MoveTo(inputPageSize.Width, 0); pdfCb.LineTo(inputPageSize.Width, inputPageSize.Height); pdfCb.Stroke(); } else { leftOffset = inputPdfReader.GetPageSizeWithRotation(i).Width; } // get page[i] from input pdf PdfImportedPage inputPage = outputWriter.GetImportedPage(inputPdfReader, i); // add page[i] to new pdf on current page with offset pdfCb.AddTemplate(inputPage, leftOffset, 0); } inputPdfDoc.Close(); } }


Merge PDF Files using iTextSharp

iText# (iTextSharp) is a port of the iText open source java library written entirely in C# for the .NET platform. iText# is a library that allows you to generate PDF files on the fly. It is implemented as an assembly.The code of the class I've written uses iText# and is based on the example code (Console Application) that can be found on http://itextsharp.sourceforge.net/examples/Concat.cs . However, this code seems to target an out of date version of iText# and can't be compiled without fixing some lines...This C#-class will allow you to merge multiple PDF's to one big PDF-file:// Based on : http://itextsharp.sourceforge.net/examples/Concat.csusing System;using System.IO;using iTextSharp.text;
using iTextSharp.text.pdf;
public class PdfMerge{public static void MergeFiles(string destinationFile, string[] sourceFiles){
try
{
int f = 0;
// we create a reader for a certain document
PdfReader reader = new PdfReader(sourceFiles[f]);
// we retrieve the total number of pages
int n = reader.NumberOfPages;
Console.WriteLine("There are " + n + " pages in the original file.");
// step 1: creation of a document-object
Document document = new Document(reader.GetPageSizeWithRotation(1));
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));
// step 3: we open the document
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;int rotation;
// step 4: we add content
while (f < sourceFiles.Length)
{
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
Console.WriteLine("Processed page " + i);
}
f++;
if (f < sourceFiles.Length)
{
reader = new PdfReader(sourceFiles[f]);
// we retrieve the total number of pages
n = reader.NumberOfPages;
Console.WriteLine("There are " + n + " pages in the original file.");
}
}
// step 5: we close the documentdocument.Close();
}
catch(Exception e)
{
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.StackTrace);
}
}
}

Tuesday, September 7, 2010

Split function in SQL server 2005

ALTER function [dbo].[fn_split](
@str varchar(8000),
@delimiter char(1)
)
returns @returnTable table (idx int primary key identity, item varchar(8000))
as
begin
declare @pos int
select @str = @str + @delimiter

while len(@str) > 0
begin
select @pos = charindex(@delimiter,@str)
if @pos = 1
insert @returnTable (item)
values (null)
else
insert @returnTable (item)
values (substring(@str, 1, @pos-1))
select @str = substring(@str, @pos+1, len(@str)-@pos)

end
return
end


Calling:
select convert(int,item) from fn_split(@stringvalue)


example:
INSERT INTO member (intid,phoneid)
select convert(int,item) ,1
from fn_split(@vchmemberid,',')