Simple 7 steps to run your first Azure Blob
Program
Introduction
Step 1:- Ensure you have
things at place
Step 2:-
What will we do?
Step 3:-
Create a web role
Step 4:- Set the blob
connection string
Step 5:- Create the blob
on webrole onstart
Step 6:- Code your ASP.NET UI
Step 7:- Run the project and enjoy
Introduction
In this section we will create our first program using Azure blobs. This article
creates a simple web page where we upload image files which are stored in azure
blobs. We have also created a simple search text box which will help us to
search the image blobs with the image file name.
In case you are a complete newbie to azure you can download my two azure basic
videos which explain what azure is all about Azure Faq Part 1 :-
Video1 , Azuer Faq Part 2 :-
Video2.
Please feel free to download my free 500 question and answer eBook which covers
.NET , ASP.NET , SQL Server , WCF , WPF , WWF@
http://www.questpond.com/ .
Step 1:- Ensure you have
things at place
In case you are a complete fresher to Azure,
please ensure you have all the pre-requisite at place. You can read the below
article to get the basic prerequisite
http://computerauthor.blogspot.com/2010/01/simple-5-steps-to-run-your-first-azure.html .
Step 2:-
What will we do?
Azure Blobs help to store large items like
files, in other words its file storage system. In this article we will create a
simple program to upload image files in Azure blob system.
Step 3:-
Create a web role
The first step is to a create a web role
project. In case you are fresher in Azure, you can go through
http://computerauthor.blogspot.com/2010/01/simple-5-steps-to-run-your-first-azure.html to understand
how to create a web role project.
So let’s create a simple project with name ‘BlobStorage’. Once you have created
the project it creates two projects one is the cloud service project and the
other is the web role project. Cloud service project has all the necessary
configuration needed for your cloud service project while the web role project
is your asp.net project.

Step 4:- Set the blob
connection string
Now the next step is to define a blob
connection string in the service configuration file. So expand the ‘BlobStorage’
project, right click on roles and select properties.

Once you select properties, go to settings tab and add the blob connection
string as shown in the below figure. In the below figure we have added blob
connection string name as ‘BlobConnectionString’.

Click on the right hand eclipse and select ‘Use
development storage’. All the changes done using the setting UI will be
reflected in the ‘ServiceConfiguration’ file as shown above.
Step 5:- Create the blob
on webrole onstart
Now it’s time to start coding. Open the web
role project and open ‘WebRole.cs’ file.

Now let’s write a code on the ‘onstart’ event
to create the blob container.
public override bool OnStart() { }
Use the ‘CloudStorageAccount’ static class to
set the configuration environment.
public override bool OnStart() { // Set the configuration file DiagnosticMonitor.Start("DiagnosticsConnectionString"); CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => { configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)); }); .... .... .... .... }
The next step is to get a reference of the
cloudstorageaccount object using the blob connection string which was provided
when you setup your web role project.
// get the blob connection string
CloudStorageAccount objStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
Once we have access to the storage account
object, use the blob end point to create the blob client.
// get the client reference
CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials);
Give a nice name to the container and create
the container object using the client object which you have just created using
the blob end point. Call the ‘CreateIfnotExist’ method of the container to
ensure that you create the blob container only if it does not exist to avoid any
errors.
// Get the reference to container CloudBlobContainer objContainer = objClient.GetContainerReference("mycontainer"); // Create the container if it does not exist objContainer.CreateIfNotExist();
Step
6:- Code your ASP.NET UI
The final step is to create the ASPX page which
will help us upload image files in the blob container which we just created in
the ‘WebRole.cs’ file. You can see in t he below figure we have create a browse
button which help us upload image files and a search text box which will help us
search blob files.
So create the below defined ASPX UI.

In the above ASPX CS UI first get the reference
to the below specified name spaces.
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
In the file upload button we need to insert the
below code snippet to upload the file. So get access to the container object
‘MyContainer’ and call the ‘GetBlobReference’ function to get access to the
cloud blob object.
// Get the storage account reference
CloudStorageAccount objStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
// get the Client reference using storage blobend point
CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials);
// Get Container reference
CloudBlobContainer objContainer = objClient.GetContainerReference("mycontainer");
// Get blob reference
CloudBlob obj =objContainer.GetBlobReference(FileUpload1.FileName.ToString());
Set the meta data of the cloud object and open
a blob stream object to write the file. Do not forget to close the blob steam
object once you are done.
// Set meta values obj.Metadata["MetaName"] = "meta"; // Open a stream using the cloud object BlobStream blobstream = obj.OpenWrite(); // Write the stream to the blob database blobstream.Write(FileUpload1.FileBytes, 0, FileUpload1.FileBytes.Count()); blobstream.Close();
Once we upload the file, we will browse through
the blob list to get the list of blobs present in the container.
// Browse through blob list from the container
IEnumerable<IListBlobItem> objBlobList = objContainer.ListBlobs();
foreach (IListBlobItem objItem in objBlobList)
{
Response.Write(objItem.Uri + "<br>");
}
In the same UI we have provided a search object
to search a blob. To search a blob first get access to the container object and
call the ‘GetBlobReference’ function with the blob name to get reference to the
cloud object.
// Get the blob reference using the blob name provided in the search CloudBlob obj = objContainer.GetBlobReference(txtSearch.Text); BlobStream blobstream = obj.OpenRead();
Read the blob stream using the blob steam
object and finally attach this stream with the Image object to display the same
in the HTTP response.
// Create the image object and display the same on the browser response
System.Drawing.Image objimg=null;
objimg = System.Drawing.Image.FromStream(blobstream,true);
Response.Clear();
Response.ContentType = "image/gif";
objimg.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Step 7:- Run the project and enjoy
Finally enjoy your first blob program. You can
see in the below figure we have uploaded some image files in the blob.
We can also search the blob using the search
blob text box and you should be able to get the below image display from the
blob database.

56 comments:
モバゲーより確実に逢えるスタービーチ♪今まで遊びをしてこなかった人でも100%であいが堪能できます。理想の異性をGETするなら当サイトにお任せください
高松宮記念の最新予想!オッズ、厳選買い目は?!レースの鍵を握る馬は裏情報を特別公開
聖なる場所スタービーチで愛を育てませんか。メル友や恋人、セクフレなど貴方が理想としている関係がスタビでは築けちゃいます。素敵なであいから発展させていきませんか
2010 競馬予想 各厩舎・調教師から届けられる最強の馬券情報を限定公開!本物の オッズ 表はコレだ
よく「彼氏いるでしょ~?」って言われるけど、イナイよσ(‾^‾)トモダチ集めてホームパーティーなんかしたりするのがマイブームでして♪♪好きな人ができてもハズかしくて告れない…(>_< )しゅりのココロをゲットしてぇ~☆コドモっぽい性格だから年上でお兄ちゃんみたいな人がタイプだよ(*^m^*) h-13-i-12@docomo.ne.jp
遂に復活!!スタービーチで素敵なであいをお楽しみ下さい
今や女の子のオナニーは常識。しかもお金を払って実際にオナニーを見てもらい、恥ずかしがるのや褒められるのが興奮のツボ!そんな彼女達とオナメールやHなことしてみませんか
誰でも楽しめるモバゲーの新感覚コミュニティー!ネットでもうひとつの生活を始めませんか
セレブラブなリッチセレブリティ達のアダルトコミュニティーサイト!お金と時間に優雅なセレブ女性達はアダルトコミュで男性との秘密交際を楽しんでいるのです
変わってるって言われるけどわりといい人だよ(笑)!!お笑い好きな人だったら話盛り上がりそうだねO(≧▽≦)O 色んなことに興味深々でおっちょこちょいだからそばで支えてくれる人募集中σ(゜-^*)自分の年齢的に年下の男の子はアウトだからごめんね(*_ _)人 u-3-ummm52@docomo.ne.jp
満を持してのスタービーチ復活劇!!ここから刻まれる、新たな一コマ。スタービーチがあなたの歴史を生み出します
【緊急】突如として消えたスタービーチが復活!長い年月をかけて不死鳥の如く蘇ったスタビをお楽しみください【緊急】
最近の不景気は、今一度自分の人生を見直すのに良い時期が来てます。こんな時代だからこそ人生の値段チェッカーで、人生の勝ち組に成る為のアドバイスを貰いませんか?ぱっと思い立った時こそ人生の分かれ道ですよ
今年も桜の季節に三冠レースの初戦が始まります。このレースで勝ち馬券を当てて、次のオークスに続ける為の、験担ぎの意味も込めて桜花賞必勝の情報を手に入れよう
モバゲーより遊べるスタービーチ!ここで自分好みの女の子を探してGETしちゃおう
新しくなったスタービーチは新しいであいのカタチを提案します★ あなたに出逢いたい人がここにいます
モバゲーよりすごいスタービーチで最高の恋をしよう!!素敵な仲間を探したい!!信頼出来る友達が欲しい…理想のパートナーと出会って理想の恋をしたい…そんなアナタに最も最適なスタビで恋の幸せ掴みとりましょう♪
今迄モテたのに最近イマイチな人、これからもモテる気配の無い人、モテて人生変えたい人、一度モテる度チェッカーを体験しませんか。良くある出合いサイトにリンクされるのでは無く、親身なアドバイス結果が出ます。これで人生が変わった人がいますよ
皐月賞・競馬予想!各厩舎・調教師から届けられる最強の馬券情報を限定公開!本物のオッズ表はコレだ
モバげーとスタビ、異性とのであいを探すならやはりこの2つのサイトは外せない。Mixiよりも遊べるサイトで楽しもう
セフレ掲示板で大人の恋愛をしてみませんか?割り切ったセフレと快楽のみを求めた恋愛をしてくださいませ
数多くある出会い系の中でも簡単に出会えるのはココ!女の子の登録人数が多いのであなたの地域のカワイイ娘もゲット出来ちゃうんです
新しくリニューアルオープンしたスタービーチでは、新しいであいのカタチを提案します☆日本で一番有名なであい系、スタビならあなたに出逢いたい人が必ず見つかります
合コンの必須うアイテムと言えば、エッチ度チェッカーと言うぐらいの知名度です。エッチ度をチェックして、気になる娘と親しくなるチャンスをつかもう。奥手の方でもその日の内にお持ち帰り出来るように、診断結果にはアドバイスも
似非スタービーチサイトが増えて来たので、愛好家で作ったサイトで口コミだけのヒッソリ運営では、出合いを求めてる方が辿り付かない現状を見かねて少し宣伝します。間違っても似非サイトには登録しないで、コチラのサイトで素敵な出合いを求めて下さい
スタービーチで友達探し!出逢い広場は簡単な無料登録するだけで使い放題でメンバー同士、気軽にメッセージのやり取りが出来るよ!女の子と出逢いのチャンスがあるかも!?詳しくはTOPページにアクセスしてみよう
釦覀莑볣莈諣莼鋦躢鷣膆臨ꪰ苣膌藣膡飣膳鿣芹뿣莼鏣莼臣膮ꧦ뒻臯벁诣莥볣芹뿣莼鏣莼臣膧ꫤ붓鏣膮膂蓣芒鿦蒟韣膦诣膕
お友達な状態です!!楽しいメールしたいので、はるによっかたらメールしてください♪ lovuv-555@docomo.ne.jp
いつでもであい放題&即逢いOK!スタビで暇な時間にであいを探そう!!であいが今までなかった人も当サイト、スタービーチなら簡単検索機能であなたの理想の方と出会えちゃう!?簡単登録で今すぐご利用いただけます
スタービーチが完全リニューアルして復活しました!!あの伝説級の出会い系サイトが満を持して再降臨。煌めくような今この瞬間にあなたの胸にもときめきをお届けします
天皇賞 春 2010 予想、オッズ、厳選買い目は?この時期のメインイベントの一つのレースがやってきた!!今年の狙うべきポイントは
誰でも知ってるモバゲーは人気SNS!当然出合いを求めてる人も多い!そこで男女が出合えるコミュニティーが誕生!ここで友達、恋人が簡単にできちゃいますよ
OLしてます☆気軽にメールくれたらほんと嬉しいです♪仲良くなったら遊びにいきたいなぁ☆ hello-kxt@docomo.ne.jp
モバゲーで探せるご近所掲示板で簡単であい!ゲーム攻略やおススメ小説情報もここでGET!ここでしか見れない裏技も公開中
スタービーチは誰にもでも幸福をもたらしてくれる。ここでだからこそ見つかるであいはきっと一生の思い出に変わります…そんな体験をあなたに。思う存分スタビをご堪能してください
2010年NHKマイルカップの鍵を握る馬の、厳選裏情報を特別公開!!情報を元に当たり馬券の量産をしよう
一時代を築いたスタービーチは閉鎖になってしまいましたが、もう一度楽しい思いをしたい、もう一度遊びたいと思う有志により再度復活しました。本家以上に簡単に会えて楽しい思いを約束します
NHKマイルC 2010 予想、オッズ、厳選買い目は?今年の狙うべきポイントを限定公開!
彼女募集中の人やフリーの人は絶対絡んでください☆ゆきとメールしよ♪ chu-chu-chulip@docomo.ne.jp
日本最大、モバゲーより面白いであい系スタービーチがついに復活、進化を遂げた新生スタビをやってみませんか?趣味の合う理想のパートナー探しの手助け、合コンパーティー等も随時開催しています。楽しかった頃のスタビで遊んでみよう
ついに帰ってきたドキドキスタービーチで素敵な恋をGETしよう♪会員数も50万人突破で以前よりも直ぐに理想の相手にであえちゃう!!恋人募集中!!友達仲間を増やしたい方必見!!素敵なであいをお楽しみ下さい☆
簡単な設問に答えるだけであなたの隠されたH度数がわかっちゃうHチェッカー!あの人のムッツリ度もバレちゃう診断を今すぐ試してみよう
今話題のツイッター、mixiやモバゲーなんか目じゃない。規制が無いに等しいから、今がチャンスなんです!!ホンマ体力が持たない位の入れ喰い状態が続いて、ツイッターを放置してた事を後悔してます
ヴィクトリアマイル 2010 予想、オッズ、厳選買い目は?人気が平然と馬券に絡む理由とは
ちょっとこんなところに書き込むのはちょっとおかしいんですけど…GWは色々楽しめました??私は結婚しているんですけどどこにも連れて行ってもらえませんでした…旦那は友達(?)とマカオに遊びに行ってます…怪しいですよね…私もスカッとパーっとしたいです♪良かったらメールしてくれる人居ませんか? sara-sarar@docomo.ne.jp
ヴィクトリアマイル 2010 予想、オッズ、厳選買い目は?今年の波乱をズバリ!確勝買い目公開中!大穴狙いのギャンブラー必見激アツ情報
モバゲータウンでであいを求めているなら当サイトへ!当コミュニティサイトは本家のモバゲータウンよりはるかにであいやすい、まさにユーザー様の為のサイトとなっております。であいをお楽しみください
飲み会やコンパで必須のSM度チェッカー、お手軽SM度診断!実は真面目な娘程、間逆なドS女王様、遊んでそうな娘はドMな奴隷願望が有るとか。診断結果を元に隠れた性癖を暴いて盛り上がろう
オークス 2010 予想 オッズ 出走馬 枠順で厳選買い目は?今年の波乱をズバリ!確勝買い目公開中!優駿牝馬はこれでもらったも同然
オークス 2010 予想 オッズ 出走馬 枠順で万馬券も夢じゃない?人気が平然と馬券に絡む理由とは!?今年の優駿牝馬は荒れるのか
もぅすぐ夏ですね☆一緒に海に行ったりしたいなヾ(>▽<)o himawari-yumeland@docomo.ne.jp
最近、話題のトゥイッターから始まる理想の関係…理想の恋をこの場で見つけていきませんか
スタービーチは誰にでも出逢いという奇跡をもたらしてくれる。スタビで理想の関係作りしてみませんか
自分の名言を一つは残しませんか、しかし考えると意外と難しい。そんな時に名言チェッカーならあなたの本当の性格を見抜けちゃいます。世界の偉人達が残した名言にはどことなく重みがあるものです
第77回 日本ダービー 2010 予想、オッズ、厳選買い目は?今年の波乱をズバリ!確勝買い目公開中!結果を出す前に結果がまるわかり
スタービーチから始まる新たな恋をしませんか?スタビ掲示板を利用して新たな恋をしていきましょう
Post a Comment