Isolated Storage in .net

It’s a one type of file system provided by .net framework. Isolated storage provides protection on the user, by application domain, assembly that is not provided by the standard file system.

To access file in Isolated storage is restricted to user who have created it. i.e Assembly X can’t access the file created in the Isolated storage of Assembly Y ,same in reverse is not possible.

Even we can restrict in application domain level, same assembly running in the different application domain can’t access the file of each others.

To Use Isolated storage we need to import System.IO.IsolatedStorage namespace. It provides the required classes for Isolated Storage.

You can create the Isolated Storage file by creating instance of IsolatedStorageFileStream class. Pass the name of your file name in the constructor. You will also find different overloaded constructor in it.

Now one common question arise in mind , Where does the file store in our file system? Because we don’t see in the our application’s folder or anywhere…

You can check that file created in the below location..

Go to your root directory from where operation system is loaded (Simply operating system is installed)

Yes now firstly from tools check to see hidden files and system files because isolated storage is hidden.

Click on the Documents and Settings, this folder contains the various users on the computer and some of the services folder all these can be viewed if you have selected to show hidden files.

Click on the user with you have logged to machine. Now you have many hidden files and folder. In that click on the Local Settings — > Application Data, that contains the folder IsolatedStorage.

This IsolatedStorage folder may have one or many folder inside of it, go to inside at last you will have Files folder and that contains your file which you have created programmatically by your application.

If you don’t find your file in the Local Settings you can also check in the Application Data folder in side the User’s folder.

Add comment February 7, 2010

Query on schema of database

In sql server we create database object like tables, function, procedure etc. Some time we need to know how many tables or procedure are there.. at that time below sql query will be useful.

SQL provides query to execute on the object of itself.

List all the Database

SELECT * FROM sys.databases

SELECT * FROM master.dbo.sysdatabases

List all the tables in the Database

SELECT * FROM sysobjects WHERE type = ‘U’

SELECT * FROM information_schema.tables

SELECT * FROM sys.tables

List all the Procedure in the Database

SELECT * FROM sys.procedures

SELECT * FROM sysobjects WHERE type = ‘P’

List all the Function in the Database

SELECT * FROM sysobjects where type=’fn’

Above syntax work correct in different version of sql server. Hope it will be useful.

Add comment February 2, 2010

Extracting Zip Files

Below is useful link to extract zip files with the use of SharpZipLib


Extract Zip File

Once file extracted you can delete the zip file using

File.Delete(zipfilePath)

Add comment January 21, 2010

ALT Key ShortCut are not Showing

Hey, it’s crazy behavior when you have assign ALT key shortcut and when you run application and don’t she underlined letters.

It’s due to your operating system settings.

Check below thing.

Right click the desktop, go to Properties, then click the Appearance tab, and then click the Effects button. You should see the setting for “Hide underlined letters for keyboard navigation until I press the Alt Key”

If its checked out then you need to press Alt key to see underlined letters. Else it will show you.

Hope it would be helpful..for me it most.

Add comment January 6, 2010

SQL Script to Find Week Days of a Year and J-Query

Add comment December 29, 2009

Image Gallery using j-query

Go through below link to show image gallery in web site with the use of J-Query

Pretty Gallery With J-Query

Its a handy plug in for the Image Gallery.

Add comment December 23, 2009

True paging using SQL script

The system gets overloaded when we fetch complete data from the database and display a fixed sized of
data per page.

Although the data is distributed among different pages however it is fetched at a longer period of time

An efficient way is to fetch data per page.

Following example helps you search news and display results accordingly by stored procedure.

CREATE PROCEDURE [dbo].[News_Search]
@SearchText nvarchar(100) –Search text,what we want ot search in news.
,@PageNo int —-Page number
,@PageSize int—–Page size
,@TotalRecords int output–Total how many records are there in search result
AS
BEGIN

SET NOCOUNT ON;
DECLARE @StartFrom int
SET @StartFrom = @PageSize * (@PageNo – 1);
SET @TotalRecords=(SELECT ISNULL(COUNT(*),0)FROM ViwNews
WHERE ViwNews.NewsIsDisable <> 0 and
@SearchText Is Null OR ViwNews.NewsTitle Like  @SearchText);

SELECT searchtable.*
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY ViwNews.NewsTitle)AS [RecNo]
,ViwNews.*
FROM ViwNews
WHERE ViwNews.NewsIsDisable <> 0 and
@SearchText Is Null OR ViwNews.NewsTitle Like  @SearchText
) AS searchtable
WHERE searchtable.RecNo > @StartFrom And searchtable.RecNo <=(@StartFrom+@PageSize);

END

I

In above query we have 4 parameters.

1) @SearchText used to pass for the search criteria.
2) @PageNo used to fetch which page number we want to fetch from the result.
3) @PageSize used to determine page size
4) @TotalRecords used to create number of pages
We can determine number of pages by dividing total records with page size.

In query we have used ROW_NUMBER() function which gives Record number obtained in the result sequentially.

Add comment December 22, 2009

Javascript to allow only numeric in text box

hi , many times we come to situation when in our website we just want to allow numeric value in text box.

This can be done by the client side java script.

Below is the script you need to insert

function isNumberKey(evt)

{

var charCode = (evt.which) ? evt.which : event.keyCode

if (charCode > 31 && (charCode < 48 || charCode > 57))

return false;

return true;

}

and here is how to attach this function to your text box either its html or asp.net text box.

onkeypress=”return isNumberKey(event)”


Add comment December 22, 2009

How to send email Asynchronously

When Our smtp Serve does not respond to immediately at that time it takes time to send email. So it happens that our application does not respond to user and user shut down our application. In this case its wise that we should send email Asynchronously and when email send successfully we just give notification it send successfully or not sent what so ever. This all things are available in the .net framework 2.0.

I am assuming that we know how to send email like to create MailMessage object then add subject,From and To address, body ,attachment etc..

Then create object of SmtpClient to send email.

After the send method call SendAsync method and pass the MailMessage Object also wire up method to SendComplete event.

//Send email

SmtpClient sc = new SmtpClient(“smtp.abc.com”);

//we have MailMessage Object mm.

sc.Send(mm);

//Wire up event of SendCompleted

sc.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);

sc.SendAsync(mm,null);

In the method of sc_SendCompleted we can cancel to sending of email, whether email is sent successfully or email encountered any error to deliver etc.

//Write method for sc_SendCompleted

void sc_SendCompleted(object sender, AsyncCompletedEventArgs e)

{

if(e.Cancelled)

{

MessageBox.Show(“Message sending is Cancelled”);

}

else if(e.Error != null)

{

MessageBox.Show(“Error to Send Email Error is:” + e.Error.ToString() );

}

else

{

MessageBox.Show(“Message sent Successfully”);

}

}

Add comment December 7, 2009

Send Image in the body of Email in .Net

Its occasionally require to send images in the body of the email. I am assuming that we have the basic idea of send email in .net. As we know to send image ,its obvious that we need to use IsHTML flag turned on. So it renders the body as HTML. In the body of HTML we can embed the image as we use in the HTML page. But it’s a bit differ as we do for the HTML page. Sometimes it happens that receipt email client does not support to render HTML in that case we should have plain text.

Alternateview and LinkedResource classes are used to do above things.

Below code demonstrates all the things.

//Create HTML message body

//Reference embed image with content ID

string htmlBody = “<html><body><h1>Hi! Picture Email</h1><br><img src=\cid:img1\></body></htm>”;

AlternateView avHtml = AlternateView.CreateAlternateViewFromString(htmlBody,null,MediaTypeNames.Text.Html);

//Create LinkedResource Object for each embedded image.

LinkedResource img1 = new LinkedResource(“c:\pic.jpg”,MediaTypeNames.Image.Jpeg);

Img1.ContentId = “img1”;

avHtml.LinkedResource.Add(img1);

//Create alternate view for unsupported clients

string textBody = “To view Image you must use email client which supports HTML message”;

AlternateView.CreateAlternateViewFromString(textBody,null,MediaTypeNames.Text.Html);

//Add the altenate view instead of body of MailMessage.Body

MailMessage mm = new MailMessage();

mm.AlternateViews.Add(avHtml);

mm.AlternateViews.Add(textBody);

//Address and Send the Message.

m.From = new MailAddress(“me@abc.com”, “My Self”);

m.To.Add(new MailAddress(“you@abc.com”,”Your Self”);

m.Subject = “Picture Message Using Alternate Views”;

SmtpClient client = new Smtpclient(“smtp.abc.com”);

client.Send(mm);

Add comment December 7, 2009

Previous Posts


Archives

Categories

 

February 2010
M T W T F S S
« Jan    
1234567
891011121314
15161718192021
22232425262728

Follow me on Twitter