Gulshan Ali's .NET Information Site
This blog is for .Net programming...
Tuesday, 6 September 2016
Wednesday, 14 May 2014
How to Extract PDF File using Itextsharp.dll (Like 500 PDF file is there but i wanna only 10 page from that file)
In this Post i am going to Explain how to extract PDF file. Suppose you have 500 Page PDF File in Original Folder and you wanna 10 only from the Original file and you want to save this 10 page in the Sample Folder.
First we need to download these .dll file from iTextSharp
itextsharp.dll
itextsharp.pdfa.dll
itextsharp.xtra.dll
and after that we need to write this code it will we working fine for me.
for more detail you can also visit: itextsharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text.RegularExpressions;
public partial class UploadFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SampleDocument();
}
public void SampleDocument()
{
DirectoryInfo directory = new DirectoryInfo(@"E:\\MY File\\EminoSoft\\File\\File\\PDFDockUpload1\\Orisinal/");
var myFile = (from f in directory.GetFiles()
orderby f.CreationTime descending
select f).First();
string sourcePdfPath = (@"E:\\MY File\\Ali\\File\\File\\PDFDockUpload1\\Orisinal/" + myFile);
string outputPdfPath = (@"E:\\MY File\\Ali\\File\\File\\PDFDockUpload1\\Sample/" + myFile);
if (!File.Exists(outputPdfPath))
{
PdfReader pdfReader = new PdfReader(sourcePdfPath);
int numberOfPages = pdfReader.NumberOfPages;
if (numberOfPages > 10)
{
ExtractPages(sourcePdfPath, outputPdfPath, 1, 10);
}
}
}
public void ExtractPages(string sourcePdfPath, string outputPdfPath, int startPage, int endPage)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
try
{
reader = new PdfReader(sourcePdfPath);
sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage));
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
for (int i = startPage; i <= endPage; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
sourceDocument.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
First we need to download these .dll file from iTextSharp
itextsharp.dll
itextsharp.pdfa.dll
itextsharp.xtra.dll
and after that we need to write this code it will we working fine for me.
for more detail you can also visit: itextsharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text.RegularExpressions;
public partial class UploadFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SampleDocument();
}
public void SampleDocument()
{
DirectoryInfo directory = new DirectoryInfo(@"E:\\MY File\\EminoSoft\\File\\File\\PDFDockUpload1\\Orisinal/");
var myFile = (from f in directory.GetFiles()
orderby f.CreationTime descending
select f).First();
string sourcePdfPath = (@"E:\\MY File\\Ali\\File\\File\\PDFDockUpload1\\Orisinal/" + myFile);
string outputPdfPath = (@"E:\\MY File\\Ali\\File\\File\\PDFDockUpload1\\Sample/" + myFile);
if (!File.Exists(outputPdfPath))
{
PdfReader pdfReader = new PdfReader(sourcePdfPath);
int numberOfPages = pdfReader.NumberOfPages;
if (numberOfPages > 10)
{
ExtractPages(sourcePdfPath, outputPdfPath, 1, 10);
}
}
}
public void ExtractPages(string sourcePdfPath, string outputPdfPath, int startPage, int endPage)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
try
{
reader = new PdfReader(sourcePdfPath);
sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage));
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
for (int i = startPage; i <= endPage; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
sourceDocument.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
How to set the position of Validation Callout Extender
In this post i am going to explain how to set Popup Position for Validator Callout Extender .
we need to create CSS class for setting popup potion like blew for Example my class name is .ValidatorYear in this example.
<dx:ASPxComboBox ID="cmbYear" runat="server" Width="180px">
</dx:ASPxComboBox>
<asp:RequiredFieldValidator ID="reqcmbYear" runat="server" ControlToValidate="cmbYear"
Display="None" ErrorMessage="SelectYear" Style="color: #FF3300" ValidationGroup="ValidateAtd"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="vccmb" runat="server" Enabled="True" TargetControlID="reqcmbYear"
CssClass="ValidatorYear">
</asp:ValidatorCalloutExtender>
And after that we have write this CSS ...
<style type="text/css">
.ValidatorYear {
left: 240px !important;
position: absolute !important;
top: 40px !important;
visibility: visible !important;
width: 180px !important;
}
.center {
margin: auto;
}
.ValidatorYear div {
border: solid 1px Black;
background-color: LemonChiffon;
position: relative !important;
}
.ValidatorYear td {
border: solid 1px Black;
background-color: LemonChiffon;
}
.ValidatorYear .ajax__validatorcallout_popup_table {
display: none;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_popup_table_row {
vertical-align: bottom;
height: 100%;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_cell {
width: 20px;
height: 100%;
text-align: right;
vertical-align: top;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_table {
height: 100%;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_table_row {
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell {
padding: 8px 0px 0px 0px;
text-align: right;
vertical-align: top;
font-size: 1px;
border: none;
background-color: transparent;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv {
font-size: 1px;
position: relative;
left: 1px;
border-bottom: none;
border-right: none;
border-left: none;
width: 15px;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv div {
height: 1px;
overflow: hidden;
border-top: none;
border-bottom: none;
border-right: none;
padding: 0px;
margin-left: auto;
}
.ValidatorYear .ajax__validatorcallout_error_message_cell {
font-family: Verdana;
font-size: 10px;
padding: 5px;
border-right: none;
border-left: none;
width: 100%;
}
.ValidatorYear .ajax__validatorcallout_icon_cell {
width: 20px;
padding: 5px;
border-right: none;
}
.ValidatorYear .ajax__validatorcallout_close_button_cell {
vertical-align: top;
padding: 0px;
text-align: right;
border-left: none;
}
.ValidatorYear .ajax__validatorcallout_close_button_cell .ajax__validatorcallout_innerdiv {
border: none;
text-align: center;
width: 10px;
padding: 2px;
cursor: pointer;
}
div.left {
height: auto;
width: 340px;
vertical-align: top;
}
div.right {
height: auto;
width: 330px;
vertical-align: top;
}
.container {
height: auto;
width: auto;
}
.container div {
display: inline-block;
}
</style>
we need to create CSS class for setting popup potion like blew for Example my class name is .ValidatorYear in this example.
<dx:ASPxComboBox ID="cmbYear" runat="server" Width="180px">
</dx:ASPxComboBox>
<asp:RequiredFieldValidator ID="reqcmbYear" runat="server" ControlToValidate="cmbYear"
Display="None" ErrorMessage="SelectYear" Style="color: #FF3300" ValidationGroup="ValidateAtd"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="vccmb" runat="server" Enabled="True" TargetControlID="reqcmbYear"
CssClass="ValidatorYear">
</asp:ValidatorCalloutExtender>
And after that we have write this CSS ...
<style type="text/css">
.ValidatorYear {
left: 240px !important;
position: absolute !important;
top: 40px !important;
visibility: visible !important;
width: 180px !important;
}
.center {
margin: auto;
}
.ValidatorYear div {
border: solid 1px Black;
background-color: LemonChiffon;
position: relative !important;
}
.ValidatorYear td {
border: solid 1px Black;
background-color: LemonChiffon;
}
.ValidatorYear .ajax__validatorcallout_popup_table {
display: none;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_popup_table_row {
vertical-align: bottom;
height: 100%;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_cell {
width: 20px;
height: 100%;
text-align: right;
vertical-align: top;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_table {
height: 100%;
border: none;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_table_row {
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell {
padding: 8px 0px 0px 0px;
text-align: right;
vertical-align: top;
font-size: 1px;
border: none;
background-color: transparent;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv {
font-size: 1px;
position: relative;
left: 1px;
border-bottom: none;
border-right: none;
border-left: none;
width: 15px;
background-color: transparent;
padding: 0px;
}
.ValidatorYear .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv div {
height: 1px;
overflow: hidden;
border-top: none;
border-bottom: none;
border-right: none;
padding: 0px;
margin-left: auto;
}
.ValidatorYear .ajax__validatorcallout_error_message_cell {
font-family: Verdana;
font-size: 10px;
padding: 5px;
border-right: none;
border-left: none;
width: 100%;
}
.ValidatorYear .ajax__validatorcallout_icon_cell {
width: 20px;
padding: 5px;
border-right: none;
}
.ValidatorYear .ajax__validatorcallout_close_button_cell {
vertical-align: top;
padding: 0px;
text-align: right;
border-left: none;
}
.ValidatorYear .ajax__validatorcallout_close_button_cell .ajax__validatorcallout_innerdiv {
border: none;
text-align: center;
width: 10px;
padding: 2px;
cursor: pointer;
}
div.left {
height: auto;
width: 340px;
vertical-align: top;
}
div.right {
height: auto;
width: 330px;
vertical-align: top;
}
.container {
height: auto;
width: auto;
}
.container div {
display: inline-block;
}
</style>
Saturday, 23 November 2013
How to use ASPxHiddenField values using Javascript
In this post i am going to Explain how to use ASPXHiddenField , and how to get HiddenField values using Javascript.
1.First we need to drag and drop ASPxHiddenField in source code. like that
1.First we need to drag and drop ASPxHiddenField in source code. like that
<div> <dx:ASPxHiddenField ID="ASPxHiddenField" ClientInstanceName="cliHidden" runat="server"></dx:ASPxHiddenField>
</div>
2. After that assign value to ASPXHiddenField control which values you want to assign.
in .CS code
ASPxHiddenField["cliHidden"] = txtEmployeeID.tex;
3.in Javascript we need to write this code..
<script type="text/javascript">
function RedirectToEntryScreen() {
var sFilter = cliHidden.Get('cliHidden');//here we get hiddinfile values
if (sFilter != "0=1")
location.href = '/Modules/HRM/ATD/ATD_ShiftAssignmentsEntry.aspx';
else if (sFilter == "0=1") {
alert("Employee does not exist for the user");
hide();
}
}
function hide()
{ setInterval(function () { ParentLoadingPnl.Hide(); }, 1); }
</script>
Note: if it will not work for you then you need to add this JQuery Library (jquery-1.7.1.min) .
Wednesday, 30 October 2013
How to Export Gridview Data to Excel Format using Asp.net
In this post i am going to Explain how to How to Convert Gridview data to Excel Format .
In Source Code we need to write EnableEventValidation="false" for Verify Rendering In Server Form
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>
first we need to Bind Gridview after that we need to write this code in button click event.
protected void btnExcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "EmployeeDetals.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in GridView1.Rows)
{
gvrow.BackColor = Color.White;
if (j <= GridView1.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
In Source Code we need to write EnableEventValidation="false" for Verify Rendering In Server Form
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>
first we need to Bind Gridview after that we need to write this code in button click event.
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "EmployeeDetals.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in GridView1.Rows)
{
gvrow.BackColor = Color.White;
if (j <= GridView1.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Create view for get Highest Salary for Each Department using SubQuery
CREATE View [dbo].[VU_SecondHSalaryEachDept]
AS
SELECT Department, MAX(TotalSalary) Salary FROM VU_EMP_Employees AS TempTable
WHERE TotalSalary <
(SELECT MAX(TotalSalary)
FROM VU_EMP_Employees
WHERE Department = TempTable.Department)
GROUP BY Department
GO
AS
SELECT Department, MAX(TotalSalary) Salary FROM VU_EMP_Employees AS TempTable
WHERE TotalSalary <
(SELECT MAX(TotalSalary)
FROM VU_EMP_Employees
WHERE Department = TempTable.Department)
GROUP BY Department
GO
Create One Stored Procedure for Insert, Update ,Select and Delete
CREATE PROC [dbo].[SP_SelectInsertUpdateDeleteEmployee]
(
@Empid int,
@EmployeeNo nvarchar(200),
@EmployeeName nvarchar(200),
@Department nvarchar(200),
@JobRole nvarchar(200),
@Salary decimal(18,3),
@DateOfJoining datetime,
@PhoneNo nvarchar(50),
@Email nvarchar(50),
@Sex nchar(20),
@StatementType nvarchar(20)=''
)
AS
Begin
if(@StatementType='Insert')
Begin
Insert into EMP_Employees(EmployeeNo,EmployeeName,Department,Salary,JobRole,DateOfJoining,PhoneNo,Email,Sex)
values(@EmployeeNo,@EmployeeName,@Department,@Salary,@JobRole,@DateOfJoining,@PhoneNo,@Email,@Sex)
End
if(@StatementType='Select')
Begin
Select * from EMP_Employees
End
if(@StatementType='Update')
Begin
Update EMP_Employees
Set EmployeeNo=@EmployeeNo, EmployeeName=@EmployeeName,Department=@Department,Salary=@Salary,JobRole=@JobRole,
DateOfJoining=@DateOfJoining,PhoneNo=@PhoneNo,Email=@Email,Sex=@Sex
where EMPID=@Empid
End
if(@StatementType='Delete')
Delete from EMP_Employees where EMPID=@Empid
End
(
@Empid int,
@EmployeeNo nvarchar(200),
@EmployeeName nvarchar(200),
@Department nvarchar(200),
@JobRole nvarchar(200),
@Salary decimal(18,3),
@DateOfJoining datetime,
@PhoneNo nvarchar(50),
@Email nvarchar(50),
@Sex nchar(20),
@StatementType nvarchar(20)=''
)
AS
Begin
if(@StatementType='Insert')
Begin
Insert into EMP_Employees(EmployeeNo,EmployeeName,Department,Salary,JobRole,DateOfJoining,PhoneNo,Email,Sex)
values(@EmployeeNo,@EmployeeName,@Department,@Salary,@JobRole,@DateOfJoining,@PhoneNo,@Email,@Sex)
End
if(@StatementType='Select')
Begin
Select * from EMP_Employees
End
if(@StatementType='Update')
Begin
Update EMP_Employees
Set EmployeeNo=@EmployeeNo, EmployeeName=@EmployeeName,Department=@Department,Salary=@Salary,JobRole=@JobRole,
DateOfJoining=@DateOfJoining,PhoneNo=@PhoneNo,Email=@Email,Sex=@Sex
where EMPID=@Empid
End
if(@StatementType='Delete')
Delete from EMP_Employees where EMPID=@Empid
End
Subscribe to:
Comments (Atom)