Florence Blogspot about asp.net tutorials and web design and web development

Thursday, December 18, 2008

Preventing Caching of htm and images being stored in Client Machine

Preventing Caching of htm and images being stored in Client Machine in Temporaray Internet Files.
Open IIS by:
1. Go to START-->RUN-->Type inetmgr
2. Click Website/Default Web Site.
3.Select Properties by Right Clicking your Virtual Directory Ex: TestApp.
4.In the Properties Dialog Box, Select HTTP Header Tab.
5.In the Custom HTTP Header Column, Click Add Button.
6. It will open another dialog box.
7. In the Add/Edit Custom HTTP Header.
1.Type "cache-control" in Header Name and
2.Type "no-cache" in Header Value
3.Click Ok
8.Again In the Add/Edit Custom HTTP Header.
1.Type "programa" in Header Name and
2.Type "no-cache" in Header Value
3.Click Ok

9.Click ok in all dialog boxes and exit from IIS.
Now check your cache in Temporary Internet Files folder.

No no no no no cache..................rit...........

How is it!!!!!!!! Coo000000000l............

Sunday, November 23, 2008

Generating pdf report using asp.net

PDF analysis by Florence.D



I have found some free components for generating pdf report using asp.net

iTextSharp.dll

ghtml2Pdf.exe

PDFSharp.dll

ApacheFop.net.dll

But I found some difficulty in the above components :

iTextSharp.dll:

In iTextSharp,

we can use 2 methods here

By passing the whole html script as string

by create a table in the code behind.

Our requirement is to generate the 1000 lines of html script into pdf.

So it is high risk to pass the 1000 lines of html script into string and also in the code behind it is not possible to create a each table in the code behind because every time the script generated may vary..
Only we can create a simple pdf not complex html scripts.

We cannot write the 1000 lines of html script into iTextSharp.dll.

ghtml2Pdf.exe:
Here we are using the exe component to generate the pdf file by passing the html file.
We have to generate the html file first and then pass that file into ghtml2Pdf.exe.
It is high riskable in the dotnet framework. Morever the we cannot use this in our whole servers.
It has the rights to work in only limited number of computers.

PDFSharp.dll

Here again we cannot use the html scripts to generate the pdf.
We have to create our own design in the codebehind. Again the same problem that every time the design or the html script may vary according to the report generated.
ApacheFop.net.dll
This is the good method to generate the pdf in dotnet using java classes.
Also we need vjslib.dll to work with the Java classess.
The process is some wat critical.
First we have to create a xml file to store the datas needed.
Then we have to create a design pattern like stylesheet using xsl.
After creating the xml and xsl, we have to transform these two and need to generate the fo file ie Formatted object file.
After the fo file created , we can generate the pdf from the fo file.
This is the structure.
But this requires some amount of time.
Using Java:
http://www.javaworld.com/javaworld/jw-04-2006/jw-0410-html.html
Here is the link where I read article for generating pdf using java.
It is a difficult process same as the above one.
Conclusion.

I have found lot of premium shareware components to generate the pdf from html.

It average costs from 600 to 1000 $.
The best is
www.winnovative-software.com
http://www.winnovative-software.com/Buy.aspx#redistributable
cost for redistributable pacakage is

INR 33938.41

Some other premium components
http://www.html-to-pdf.net/Pricing.aspx

Hope all got some knowledge anyone who started creating pdf.

Exporting WebPage to Excel using Javascript.

Refered from : Javascript

Export2Excelinjavascript

Monday, August 11, 2008

Yahoo contacts!!! import class in C#

I tried to find free Yahoo! Contact import code for .NET platform. I found only paid packages for 300+$.


I've implemented importing and you can use it for free.
(But you need to make some change in code to compile it)




using System;

using System.Collections.Specialized;

using System.Net;

using System.Text;

using System.Text.RegularExpressions;



namespace Gnilly.Syndication.Mail

{

public class YahooExtract

{

private const string _addressBookUrl = "http://address.yahoo.com/yab/us/Yahoo_ab.csv?loc=us&.rand=1671497644&A=H&Yahoo_ab.csv";

private const string _authUrl = "https://login.yahoo.com/config/login?"; private const string _loginPage = "https://login.yahoo.com/config/login";

private const string _userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";





public bool Extract( NetworkCredential credential, out MailContactList list )

{

bool result = false;





list = new MailContactList();





try

{

WebClient webClient = new WebClient(); webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent; webClient.Encoding = Encoding.UTF8;





byte[] firstResponse = webClient.DownloadData( _loginPage );

string firstRes = Encoding.UTF8.GetString( firstResponse );



NameValueCollection postToLogin = new NameValueCollection();

Regex regex = new Regex( "type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\"", RegexOptions.IgnoreCase );

Match match = regex.Match( firstRes );

while ( match.Success )

{

if ( match.Groups[ 0 ].Value.Length > 0 )

{

postToLogin.Add( match.Groups[ 1 ].Value, match.Groups[ 2 ].Value );

}

match = regex.Match( firstRes, match.Index + match.Length );

}





postToLogin.Add( ".save", "Sign In" );

postToLogin.Add( ".persistent", "y" );





string login = credential.UserName.Split( '@' )[ 0 ];

postToLogin.Add( "login", login );

postToLogin.Add( "passwd", credential.Password );





webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;

webClient.Headers[ HttpRequestHeader.Referer ] = _loginPage;

webClient.Encoding = Encoding.UTF8;

webClient.Headers[ HttpRequestHeader.Cookie ] = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];



webClient.UploadValues( _authUrl, postToLogin );

string cookie = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];





if ( string.IsNullOrEmpty( cookie ) )

{

return false;

}





string newCookie = string.Empty;

string[] tmp1 = cookie.Split( ',' );

foreach ( string var in tmp1 )

{

string[] tmp2 = var.Split( ';' );

newCookie = String.IsNullOrEmpty( newCookie ) ? tmp2[ 0 ] : newCookie + ";" + tmp2[ 0 ];

}





// set login cookie

webClient.Headers[ HttpRequestHeader.Cookie ] = newCookie;

byte[] thirdResponse = webClient.DownloadData( _addressBookUrl );

string thirdRes = Encoding.UTF8.GetString( thirdResponse );





string crumb = string.Empty;

Regex regexCrumb = new Regex( "type=\"hidden\" name=\"file://.crumb/" id=\"crumb1\" value=\"(.*?)\"", RegexOptions.IgnoreCase );

match = regexCrumb.Match( thirdRes );

if ( match.Success && match.Groups[ 0 ].Value.Length >) )

{

crumb = match.Groups[ 1 ].Value;

}





NameValueCollection postDataAB = new NameValueCollection();

postDataAB.Add( ".crumb", crumb );

postDataAB.Add( "vcp", "import_export" );

postDataAB.Add( "submit[action_export_yahoo]", "Export Now" );





webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;

webClient.Headers[ HttpRequestHeader.Referer ] = _addressBookUrl;



byte[] FourResponse = webClient.UploadValues( _addressBookUrl, postDataAB );

string csvData = Encoding.UTF8.GetString( FourResponse );



string[] lines = csvData.Split( '\n' ); foreach ( string line in lines )

{

string[] items = line.Split( ',' );

if ( items.Length < 5 )

{ continue;

}

string email = items[ 4 ];

string name = items[ 3 ];

if ( !string.IsNullOrEmpty( email ) && !string.IsNullOrEmpty( name ) )

{

email = email.Trim( '\"' );

name = name.Trim( '\"' );

if ( !email.Equals( "Email" ) && !name.Equals( "Nickname" ) )

{

MailContact mailContact = new MailContact();

mailContact.Name = name;

mailContact.Email = email;

list.Add( mailContact );



}

}

}





result = true;

}

catch

{

}

return result;

}

}

}

Search