05
Dec
2008
0

Consuming RSS feed in ASP.NET

Thanks to RSSToolKit, an open source component you can find at codeplex, consuming a RSS field to display, for instance, in your website has never been so easy.

Here is the code we use to display 3 posts of this blog on the official phoceis.com website (in a literal named lit_blog)

RssDocument rdoc = RssToolkit.Rss.RssDocument.Load(new System.Uri("http://blog.phoceis.com/feed/rss/"));
DataView dv = (DataView) rdoc.SelectItems(3);
lit_blog.Text = "
<ul>";
foreach (DataRow dr in dv.Table.Rows)
{
	lit_blog.Text += "
	<li><a href='" + dr["link"].ToString() + "' target="_blank">" + dr["title"].ToString() + "</a></li>";
}
lit_blog.Text += "</ul>";
Ecrit par julien dans : .NET | Tags : , ,
27
Nov
2008
0

Grab a file from the web and store it in your database using c#

If you want to download a file from the web and store it directly in a kind of blob field in your database

string url = "the url of the file you want to download";
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
using (BinaryReader br = new BinaryReader(stream))
{
	b = br.ReadBytes((int)stream.Length);
        br.Close();
}
myResp.Close();
// say we have a LINQ datacontext named "context", an entity video with a varbinary(max) 
// field named preview to store the content of the file (for instance a picture)
video vid = new video();
vid.preview = b;
context.videos.InsertOnSubmit(vid);
context.SubmitChanges();
Ecrit par julien dans : .NET | Tags : , ,
27
Nov
2008
0

Retrieve video details from YouTube using c#

Below is a code to retrieve a YouTube video’s details using the Google API.
You may first download and install the Google Data Api, and apply for a developer ID.

YouTubeService service = new YouTubeService("example app", "ytapi-Phoceis-Youtubeforkids-jktgue07-0", "AI39si6XU6CYi6Qo52i7qD7OLEZ7JBebKPGgHAzmN34UF23HRBYtcT7B_eWvoiTCDCaO7ePAaCFs6aCzeNNR535shbeH63IXNQ");
 
String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/" + ID_of_your_video;
YouTubeEntry videoEntry = (YouTubeEntry)service.Get(videoEntryUrl);
 
if (videoEntry != null)
{
            tex_titre.Text = videoEntry.Title.Text;
            if (videoEntry.Media.Thumbnails.Count &gt; 0)
            {
                // here we populate an aspxcombobox (a component from DevExpress) with the collection of thumbnails of the video, but you may also use classic radiobutton
                com_images.DataSource = videoEntry.Media.Thumbnails;
                com_images.ImageUrlField = "Url";
                com_images.TextField = "Url";
                com_images.DataBind();
                com_images.SelectedIndex = 0;
            }
            tex_kw.Text = videoEntry.Media.Keywords.Value;
            lab_length.Text = videoEntry.Duration.Seconds.ToString();
}
Ecrit par julien dans : .NET | Tags : , , , ,

Propulsé par WordPress | Thème Aeros | TheBuckmaker.com WordPress Themes | Traduction WordPress tuto