Saturday, January 19, 2013

C# zip unzip using window shell

If you want to zip / unzip files using C# code .yes its easy and you can do that without using any third party tools. using simple dll (Windows Shell32) you can do that quickly.

Just find below steps.

1.Create new project in Visual Basic 2010.
2.From the main menu, select Project -> Add Reference.
3.Select the COM tab and search for Microsoft Shell Controls and Automation.  



 Try using below code and zip/unzip your code.

Public Class Form1
 
    Sub Zip()
        '1) Lets create an empty Zip File .
        'The following data represents an empty zip file .

        Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, _
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 
        ' Data for an empty zip file .
        FileIO.FileSystem.WriteAllBytes("d:\empty.zip", startBuffer, False)
 
        'We have successfully made the empty zip file .

        '2) Use the Shell32 to zip your files .
        ' Declare new shell class
        Dim sc As New Shell32.Shell()
        'Declare the folder which contains the files you want to zip .
        Dim input As Shell32.Folder = sc.NameSpace("D:\neededFiles")
        'Declare  your created empty zip file as folder  .
        Dim output As Shell32.Folder = sc.NameSpace("D:\empty.zip")
        'Copy the files into the empty zip file using the CopyHere command .
        output.CopyHere(input.Items, 4)
 
    End Sub
 
    Sub UnZip()
        Dim sc As New Shell32.Shell()
        ''UPDATE !!
        'Create directory in which you will unzip your files .
        IO.Directory.CreateDirectory("D:\extractedFiles") 
        'Declare the folder where the files will be extracted
        Dim output As Shell32.Folder = sc.NameSpace("D:\extractedFiles")
        'Declare your input zip file as folder  .
        Dim input As Shell32.Folder = sc.NameSpace("d:\myzip.zip")
        'Extract the files from the zip file using the CopyHere command .
        output.CopyHere(input.Items, 4)
 
    End Sub
 
End Class
 

Sunday, May 6, 2012

delete existing store procedure and tables

Delete all existing database use this scripts.
    
DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
BEGIN
Exec SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?
GO



if you want to delete all existing store procedure use this scripts.



DECLARE @procedureName varchar(500)
DECLARE cur CURSOR
      FOR SELECT [name] FROM sys.objects WHERE type = 'p'
      OPEN cur

      FETCH NEXT FROM cur INTO @procedureName
      WHILE @@fetch_status = 0
      BEGIN
            EXEC('DROP PROCEDURE ' + @procedureName)
            FETCH NEXT FROM cur INTO @procedureName
      END
      CLOSE cur
      DEALLOCATE cur
 
Hope it will help you :)


Monday, March 28, 2011

Export Gridview to PDF

we have seen how to export the data from gridview to Excel file, today this post will helps you to export the gridview data to PDF, if you want protect you data being edit/ cut/ delete then Export to PDF will be a better option for you.there is a open source project for iTextShart. you can download the dll from them and you can use it.

only you need to add this content on your page

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename= SampleExport.pdf");
Response.End();


Even you can format the text also,if you want to set the page with A4 or any other even you can also do the same.you can also specify the font size, style color all the basic things you can do with it.

you can download the code from the below link. you can try that it will helps you.

download Source

Sunday, July 18, 2010

how to add related posts on Blogger

we have seen on most of the blogger site , "Related post" section is there after every post now you want to add this Related post / Similar post on your blog ? follow the below easy steps and configure you blogger accordingly.

  • Open blogger.com site

  • Go to Design section under that you will get Edit Html Tab just click on it.

  • now before making any changes on your xml file just take abackup for safty

  • just click on "Expand widget templates "

  • Add the below code above the </head > section or better way is search the keyword </head>

    <script src='https://www.opendrive.com/files/6673148_cnSMd/RelatedPosts_Blogger.js' type='text/javascript'/>


  • now search for code <data:post.body/>

  • After this paste the below code line



  • <b:if cond='data:blog.pageType == "item"'>
    <div id='related-posts'>
    <font face='Arial' size='3'><b>Related Posts: </b></font><font color='#000000'><b:loop values='data:post.labels' var='label'><data:label.name/><b:if cond='data:label.isLast != "true"'>,</b:if><b:if cond='data:blog.pageType == "item"'>
    <script expr:src='"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"' type='text/javascript'/></b:if></b:loop> </font>
    <script type='text/javascript'> removeRelatedDuplicates(); printRelatedLabels();
    </script></div></b:if>



  • now on the above code you will see the red section line "max-results=xx" here you can enter no of post you want to see on your page
    accordingly you can mention it.

  • now save you template and see the magic on your post

  • you will see the number of post after each article , before that you need to add label on your post. hope you like it


  • if you face any problem while doing this plz leave a comment.

Friday, June 11, 2010

How strong name assemblies keep you out of DLL Hell

while using Microsoft .NET framework for creating any application we are previously facing same problem with the DLL Hell. it arises a problem while updating a components so it breaks the other application which are depend on it. to overcome such a issues developer needs to implement the concept of Strong name .In this article you can through with how and why to use strong name .

Strong Name :
what is strong name? A Strong name is of information used to identify the assembly which may consist of Text-name , four part of version number , culture information , public key and the digital signature which may stored in a assembly manifest that get embedded on the file of the assembly.

By using the Strong name the CLR can assured that two assembly can be there with the same name. by the way strong name is basically provided the unique identification of the assembly. there are two scenarios in which the strong name can included in the assembly
1.Shared Assemblies
2. Serviced Components.

on the first case the shared assemblies can be used in the multiple application which may running on the same machine on GAC. and you may get the benefit ares:
1. Single Development
2. Bypass verification
3. Centralized update

yes as your getting such a good benefits then surely there is also a some issues on it that is
1.calling a private assemblies : if the shared assemblies can load with the type of private assembly then CRL will throw an Error because it reference only shared assemblies.
2. Trusting assemblies :
3. Installation issues :

How to create "Strong Name".
To create strong name for assembly you need a (al.exe) tool which is a assembly generation tool .now to create a key pair in the file you can use Strong name utility (Sn.exe) like this way.
Sn.exe -k filename.dat

The key file could be used on Al.exe to generate the strong name.
Al.exe /out:Input.dll /Keyfile:output.dat

Like this way you can design your strong name with the key. hope you get something from this
if you have any query on it plz post the reply.

Sunday, April 25, 2010

my oracle interview experience

hi friends,

last week i was attended "ORACLE financial services" interview for the .NET Developer post. Here i am sharing my experience on interview hope so it will help you while going for an Oracle Interview. i was disqualify from 3rd Round (Final Technical Round).

Interview Process:
There was 4 Round 1 st Online Test ( 47 Question 1 hrs ) but be careful there is also a negative marking as well as there is also a cutoff (if u select more than 1 answer and answer is wrong ) then again some deduction on your marks . Quite tough mostly Question on Assembly , Framework , C# , then hardly question on Datalist,Datagrid, Gridview and all basic. we totally 3 people get selected in first round out of 10.

Second Round is Technical Round. it was ok only basic question get ask during the interview , but in most of them are in-depth question just like on DataGrid DataBind() wht happen exactly , which function get executed at first onRowDataBound() or DataBind(). how .net life cycle will work on this process and all . i also got selected on this round .

now There was a Final Round on again Technical . There was 2 panelist in front of me and asking question on most of the SDLC (Software Development Life Cycle) and Question on backed on Pl-sql / SQL2005 . i thing around 15+ question get ask during the interview process i have answer most of them . but interview was cool .

at last there was an only final Round Remaining which is HR Round. but sorry to say friends i was disqualified from this process (2nd Technical Round). hope my this experience will help you to get it in ORACLE or any other software farm .because most of the time same process is there every where .

hope i will get good company out of this. better luck next time .but one thing is sure i am getting very good experience from this.

Sunday, April 18, 2010

Jquery 1.4.1 released

very good news to all the Jquery users and jquery lovers. the latest version of Jquery ( which is 1.4.1 has been released).it has lot of improvement on bases of performance , new additonal features and many new functions are added to make
jquery very popular. i really enjoy with the same. as you can see the execution time of realease version is very less in time as compare with the previous one.
here are the Minified and Regular version .



You can download the js frem the above link.or you can take a advantage of Google CDN on : http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
while using CDN one is very good idea , because if anything get change on current realease then it will automatically updated on your application ,. if your using Google CDN features , Microsoft is also providing the same kind of feature of CDN you can also take the help form there also.

on new release they have added methds like , Setter , Getter and many more ajax features. the Whole API Documentation you
can get it from here. http://api.jquery.com/category/version/1.4/

now guys why your waiting , just use latest version of Jquery on your application and make your application very cool and attractive .