TEST

Blog Pages

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,',')







Comma Separated value in SQL

create function [dbo].[commaSeperateValue]
(
@inttypeid int,
@intmemberid int,
@parametertypeid int
)
returns varchar(1000)
as
begin

declare @Values varchar(1000)

if @inttypeid = 1 -- buiding types
select @Values = Stuff((SELECT DISTINCT ', ' + vchBuildingType AS [text()]
FROM member_building_type mbt inner join building_type bt on bt.intbuildingtypeid=mbt.intbuildingtypeid
and bt.bitIsActive=1 and mbt.intmemberid = @intmemberid and mbt.intBuildingTypeId = (case when @parametertypeid = 0 then mbt.intBuildingTypeId else @parametertypeid end)
FOR XML PATH ('')),1,1,'')

if @inttypeid = 2 -- Role types
select @Values = Stuff((SELECT DISTINCT ', ' + vchRoleName AS [text()]
FROM email_template_roles mbt inner join [role] bt on bt.introleId=mbt.introleId
and bt.bitActive=1
where mbt.intTemplateId=@intmemberid
FOR XML PATH ('')),1,1,'')

if @inttypeid = 3 -- Services
select @Values = Stuff((SELECT DISTINCT ', ' + vchServiceType AS [text()]
FROM member_setting_zipcode msz
inner join service s on s.intServiceId=msz.intserviceid
inner join service_type st on st.intServiceTypeId=s.intServiceId
and msz.intserviceid = (case when @parametertypeid = 0 then msz.intserviceid else @parametertypeid end)
and msz.intmemberid=@intmemberid
FOR XML PATH ('')),1,1,'')
return @Values

end



Calling :

select dbo.lookup_types_commaSeperate (2,4,0)


Output:
Admin, Chapter President,Inspector,Contractor





Get Address image from Google Map and Add it into iTextSharp Document PDF

//iTextSharp.text.Image LocationImage = iTextSharp.text.Image.GetInstance("http://maps.google.com/maps/api/staticmap?center=" + objInspMgt.PropertyInspectedAddress + "&zoom=14&size=612x612&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|41.726247,-97.002853&sensor=false");

//Map style roadMap
iTextSharp.text.Image LocationImage = iTextSharp.text.Image.GetInstance("http://maps.google.com/maps/api/staticmap?size=412x530&maptype=roadmap&markers=size:mid|color:red|"+objInspMgt.PropertyInspectedAddress+"&sensor=false");

//Map style terrain
//iTextSharp.text.Image LocationImage = iTextSharp.text.Image.GetInstance("http://maps.google.com/maps/api/staticmap?size=412x530&maptype=terrain&markers=size:mid|color:red|" + objInspMgt.PropertyInspectedAddress + "&sensor=false");

//Map style satellite
//iTextSharp.text.Image LocationImage = iTextSharp.text.Image.GetInstance("http://maps.google.com/maps/api/staticmap?size=412x530&maptype=satellite&markers=size:mid|color:red|"+objInspMgt.PropertyInspectedAddress+"&sensor=false");

//Map style hybrid
//iTextSharp.text.Image LocationImage = iTextSharp.text.Image.GetInstance("http://maps.google.com/maps/api/staticmap?size=412x530&maptype=hybrid&markers=size:mid|color:red|" + objInspMgt.PropertyInspectedAddress + "&sensor=false");


LocationImage.ScaleToFit(650, 650);
LocationImage.Alignment = iTextSharp.text.Image.UNDERLYING;
LocationImage.SetAbsolutePosition(0, 0);
locationcell = new PdfPCell(LocationImage);
locationcell.PaddingBottom = 10;
locationcell.PaddingTop = 10;
locationcell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
locationcell.Colspan = 3;
locationcell.Border = 0;

Locationtable.AddCell(locationcell);
Document.Add(Locationtable);





Wednesday, August 25, 2010

Convert Html to Pdf using iTextSharp

This is iTestSharp 4.1.2 version and in Asp.net(C#)

Add the iTestSharp dll by adding it as Add Reference into your project and then you create a aspx,ascx page and write the below code into a function and call it from any event or add this function name into page_load event.


using System;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using iTextSharp.text;
using System.Data;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
using System.Web;

private void GeneratePdf()

{

Console.WriteLine("Report");

MemoryStream m = new MemoryStream();

//Response.ContentType = "application/pdf";

//Response.AddHeader("content-disposition", "attachment;filename=VisualROOF Inspection.pdf");

//Response.Cache.SetCacheability(HttpCacheability.NoCache);

// step 1: creation of a document-object

Document document = new Document();


try
{
// step 2

// we create a writer that listens to the document

// and directs a PDF-stream to a file

//PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); PdfWriter writer = PdfWriter.GetInstance(document, m);

writer.CloseStream = false;
// step 3:

// we Add a Footer that will show up on PAGE 1

Paragraph para = new Paragraph("©2009 NRCIA",FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL,new Color(102,45,25)));

para.Add(Environment.NewLine);

para.Font =FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL,new Color(237,28,36));

para.Add("This document is not a certification");

HeaderFooter footer = new HeaderFooter(para, false);

footer.Alignment = Element.ALIGN_CENTER;

document.Footer = footer;
// we open the document

document.Open();
// we rotate the page and add background image, starting from PAGE 2 document.SetPageSize(PageSize.A4.Rotate());

document.SetMargins(10f,10f,10f,10f);
// step 4: we Add content to the document

// PAGE 1

//add image into pdf

Image pdfImage = Image.GetInstance(Server.MapPath("/images/reports/inspection/InspectionReportImage.jpg"));

pdfImage.ScaleToFit(3500, 845);

pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(2, -5);

document.Add(pdfImage);
// Empty table for spacing

PdfPTable emptytable = new PdfPTable(3);

emptytable.TotalWidth = 560f;

emptytable.HorizontalAlignment = Element.ALIGN_CENTER;

emptytable.LockedWidth = true;

PdfPCell cell1 = new PdfPCell();

cell1.Padding = 60;

cell1.Colspan = 3;

cell1.Border = 0;

emptytable.AddCell(cell1);

document.Add(emptytable);

///actual table for data

/// PdfPTable table = new PdfPTable(3);

table.TotalWidth = 400f;

table.HorizontalAlignment = Element.ALIGN_CENTER;

table.LockedWidth = true;

float[] widths = new float[] { 30f, 50f,50f };

//set the column widths

table.SetWidths(widths);

// Report No header name for cell
PdfPCell cell = new PdfPCell(new Phrase("Report No:", new Font(fBoldHeading, 10, 0, new Color(102, 45, 25))));

cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right

cell.Border = 0;

table.AddCell(cell);
// header Prepared Exclusively for cell

cell = new PdfPCell(new Phrase("Prepared Exclusively for:", new Font(fBoldHeading, 10, 0, new Color(102, 45, 25))));

cell.HorizontalAlignment =1; //0=Left, 1=Centre, 2=Right

cell.Border = 0;

table.AddCell(cell);
cell = new PdfPCell(new Phrase(ReportNo, new Font(fBoldHeading, 10, 0, new Color(0, 0, 0))));

cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right

cell.Border = 0;

table.AddCell(cell);
// Prepared Exclusively Value for cell

cell = new PdfPCell(new Phrase(objInspMgt.PreparedFor, new Font(fBoldHeading, 10, 0, new Color(0, 0, 0))));

cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

cell.Border = 0;

table.AddCell(cell);
//Add table to Document for First Page

document.Add(table);
//we remove the footer and new footer for page 2

document.ResetFooter();

// we reset the page numbering

//document.ResetPageCount();
// we Add a Footer that will show up on PAGE 2

Phrase para1 = new Phrase("©2009 This document is not a certification.", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL, new Color(237, 28, 36)));

string spce = " ";

footer = new HeaderFooter(para1, false);

footer.Alignment = Element.ALIGN_CENTER;

footer.Border = Rectangle.TOP_BORDER;

footer.BorderWidthTop = 2;

footer.BorderColorTop = new Color(58, 38, 5);

footer.Bottom = 20f;

document.Footer = footer;
// set page size for all pages

document.SetPageSize(PageSize.A4);

document.SetMargins(10f, 10f, 0f, 10f);
// we trigger a page break Table OF CONTENT

document.NewPage();

// we Add some more content

}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
// step 5: we close the document

document.Close();

// step 6: Write pdf bytes to outputstream

//Response.Write(document);

//Response.End();

Response.ContentType = "application/pdf";

Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush();

Response.OutputStream.Close();

m.Close();

}




Tuesday, February 16, 2010

Add a new field in com_contact administrator view

how we add a new field in com_contact administrator?
Ans:
the below files are exist in Administrator Folder ->components->com_contact

"/com_contact/admin.contact.html.php"
Added just above contact position around line 355

Code:


<>

< class="key" valign="top">

< for="region">< ?php echo JText::_( 'Region' ); ?>:< /label>< /td>

<>

< class="inputbox" type="text" name="region" id="region" size="60" maxlength="255" value="">region; ?>" />

< /td>

< /tr>




"/com_contact/tables/contact.php"
Added just under "alias" string:

code:

"var $region = null;

/** @var string */"


In MySQL:

Code:

"mysql> ALTER TABLE jos_contact_details ADD region VARCHAR(60) AFTER alias;"





Change the readmore link text in joomla

To change the "read more" text
Follow these steps:
-Go to language folder
-Open the en-GB folder
-Find the respective file name like "en-GB.mod_newsflash.ini" or any other, in which the "readmore" link exists.
-Find the read more text in this file and replace it.
Note : In this method its only effect on the module or component you selected, not the whole application.


good luck