Image to Byte Array conversion

Convert Image to byte[] array:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}

Advertisements

301 permanent redirects and ASP.Net 4.0

Hello all,

In this post, I would like to talk about a new method of the Response object that comes with ASP.Net 4.0.

The name of the method is RedirectPermanent.

Let’s talk a bit about 301 redirection and permanent redirection.301 redirect is the most efficient and Search Engine Friendly method for webpage redirection.

Let’s imagine that we have this scenario. This is a very common scenario. We have redesigned and move folders to some pages that have high search engine rankings. We do not want to lose those rankings.

We can permanently redirect traffic to the new pages without losing page rankings by using the 301 permanent redirect. RedirectPermanent help us to achieve that.

In order to demonstrate this new helper method, I will create the default asp.net website that comes with asp.net 4.0.

1) Fire VS 2010 and create a new website. Choose the filesystem to save your website ann VB as the .net language for this website

This is a much richer template that the previous ones that were created with VS 2008.

We have a Home page and an About page.

2) Create a new page and call it NewAbout (NewAbout.aspx)

3) Write some dummy content on it like “This is our new About us page”

4) Move to the About.aspx.vb, and in the page load event, type the following

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.RedirectPermanent(“~/NewAbout.aspx”)
End Sub

5)  Now run your application and then click “About” page. You will permanently redirect to the new “NewAbout” page.

Hope it helps!!!!

Fetch data from another website

// used to build entire input
StringBuilder sb = new StringBuilder();

// used on each read operation
byte[] buf = new byte[8192];

// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(“http://www.bseindia.com/mktlive/groupgain.asp”);

// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();

// we will read data via the response stream
Stream resStream = response.GetResponseStream();

string tempString = null;
int count = 0;

do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);

// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);

// continue building the string
sb.Append(tempString);

}
}
while (count > 0); // any more data to read?

Response.Write(sb.ToString());

New in ASP.NET 4.0, Visual Studio 2010

There are many new things given by Microsoft this times.. i listed some below.

1. Code Snippets
2. New Profiles
3. Generate From Usage
4. Multi-Monitor Support
5. Code Navigation in Class Files
6. Intellisense Improvements
7. EnablePersistedSelection
8. Web.Config Transformation
9. URL Routing
10. Add Reference Dialog
11. Compressing Session Values

and many more…

Please check out

http://www.codeproject.com/KB/aspnet/Whatis_New_ASP_Net_4.aspx

You can also find here “what’s new in C#.net 4.0”

Enjoy Programming…

%d bloggers like this: