in

ASP.NET Weblogs

Tolga Koseoglu

  • Silverlight group in InsideTech...

    Please join my Silverlight group in InsideTech at http://insidetech.monster.com/groups/193-silverlight-developers

     

  • Silverlight 3 + .net RIA services + FlickrNet

    So, I was challenged with writing a custom company Flickr upload screen. Since I have been working with Silverlight 3 and .net RIA Services a lot in the past few months I decided to go that route.

    Initial research revealed that there was a .net library for Flickr stuff. Great...and it's free too.

    My next challenge was to figure out how to use .net RIA services without any database stuff. Until this projcet, my .net RIA projects all had database back-ends. At the end it was not complicated and actually the .net RIA Document helped and well as the forums.

    So, here are the steps to create a custom DomainService without data model.

    1. Create you custom class

    2. Create a list class from that

    3. Create your metaadata class

    4. Create your domain service

    Below you will find code to those 4 steps. After that everything the same as if you were to develop a vanilla .net RIA Silverlight application. For more info on that check out silverlight.net video tutorials on .net ria services.

     

    1. Custom Class 

    using System.ComponentModel.DataAnnotations;
    using System;
     
    namespace Flickrv2.Web
    {
        public partial class FlickrImage
        {
            [Key]       
            public string Title { get; set; }
            [Key] 
            public string Description { get; set; }
            [Key] 
            public string Tags { get; set; }
            [Key] 
            public string FileName { get; set; }       
            public Byte[] ImageData { get; set; }        
            public String URL { get; set; }
        }
    }

    2. Create a list class from that.

    using System.Collections.Generic;
    namespace Flickrv2.Web
    {
        public class FlickrImageList
        {
            private List<FlickrImage> list = new List<FlickrImage>();
            public FlickrImageList()
            {
            }
            public IEnumerable<FlickrImage> GetFlickrImages()
            {
                return list.ToArray();
            }
            public void AddFlickrImage(FlickrImage image)
            {
                list.Add(image);
            }
        }
    }
     
    3. Create the .metadata class
    using System.ComponentModel.DataAnnotations;
    using System;
    using System.ComponentModel;
     
    namespace Flickrv2.Web
    {
        [MetadataType(typeof(FlickrImage.FlickrImageMeta))]
        public partial class FlickrImage
        {
            internal sealed class FlickrImageMeta
            {           
                [Required(ErrorMessage = "Title is required")]
                [Display(Name = "Please enter a title", Description = "Please enter the image title")]
                public string Title { get; set; }
     
                [Required(ErrorMessage = "Description is required")]
                [Display(Name = "Please enter a description", Description = "Please enter an image description")]
                public string Description { get; set; }
     
                [Required(ErrorMessage = "Tags are required")]
                [Display(Name = "Please enter tags", Description = "Please enter tags for the image")]
                public string Tags { get; set; }
     
                [Required(ErrorMessage = "Image is required")]
                [Display(Name = "Please chose an image", Description = "Select an image.")]            
                public string FileName { get; set; }
     
                public Byte[] ImageData { get; set; }
     
                public String URL { get; set; }
            }
     
        }
    }
     
    4. Finally, create your Domain Serivice class
     
    using System.Web.DomainServices;
    using System.Web.Ria;
    using System.Linq;
    using System.IO;
    using System.Configuration;
    using FlickrNet;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Collections.Generic;
     
    namespace Flickrv2.Web
    {
        [EnableClientAccess()]
        public class FlickrImageDomainService : DomainService
        {
            FlickrImageList Context = new FlickrImageList();
     
            public IQueryable<FlickrImage> GetImages()
            {
                return Context.GetFlickrImages().AsQueryable();
            }
     
            public IQueryable<FlickrImage> GetImage(String Title)
            {
                return Context.GetFlickrImages().ToList().Where(img => img.Title == Title).AsQueryable();
            }
     
             
            public void InsertImage(FlickrImage image)
            {
                var title = image.Title;
                var description = image.Description;
                var tags = image.Tags;
                var data = this.ConvertImageDataToStream(image.ImageData);
     
                var flickr = new FlickrNet.Flickr
                {
                    AuthToken = ConfigurationManager.AppSettings["FlickrAuthtoken"]
                };
     
                var flickr_id = flickr.UploadPicture(data,
                           title, description, tags, 0, 0, 0, FlickrNet.ContentType.Photo, SafetyLevel.None, HiddenFromSearch.Visible);
     
                var flickrPhotos = flickr.PhotosGetSizes(flickr_id);
     
                image.Title = title;
     
                if (flickrPhotos.SizeCollection.Count() > 3)
                    image.URL = flickrPhotos.SizeCollection[3].Source;
                else
                    image.URL = flickrPhotos.SizeCollection[2].Source;            
            }
            
            public override void Submit(ChangeSet changeSet)
            {
                base.Submit(changeSet);
            }
     
            private Stream ConvertImageDataToStream(Byte[] _data)
            {
                return new MemoryStream(_data);
            }
        }
                        
    }
     
     
    Here is some code from the client (Silverlight 3) on how to do the upload...
     
    private FlickrImageDomainContext dc = new FlickrImageDomainContext();
    private SubmitOperation soUploadNewImage; 
     
    void DoUpload()
            {
                try
                {               
                    img.ImageData = this.m_bImageData;
                    this.dc.FlickrImages.Add(img);
                    this.soUploadNewImage = this.dc.SubmitChanges();
                    this.soUploadNewImage.Completed += new EventHandler(loUploadImage_Completed);
                }
                catch (Exception ex)
                {
                }
     
  • Building SharePoint Tools (Part 1)

    In my previous post I wrote about how to get up-to-speed with a SharePoint installation and web part development. I talked about installation challenges and what helpful tools to use when trying to development SharePoint web parts. Now that your environment is ready I need some tool to discover and explore it. In other words we need to build us tools that utilize the SharePoint object model or SharePoint's web services.

    Part 1 or Show me all existings sites (webs) in an existing SharePoint environment 

    So, this is a basic C# forms application with references Microsoft.SharePoint.dll. Here is the code...

    private void btnGetSourceSites_Click(object sender, EventArgs e)

            {
                this.tvSites.Nodes.Clear();
     
                //OM
     
                this.BuildSitesTreeFromOM();
     
                //WEB SERVICE
                tn = new TreeNode();
                tn.Text ="Root";
                this.tvSites.Nodes.Add(tn);
                this.BuildSitesTreeFromService(this.txtSourceSC.Text, tn);
                this.tvSites.ExpandAll();
            }
     
            //OM
            private void BuildSitesTreeFromOM()
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite spsite = new SPSite(this.txtSourceSC.Text))
                        {
                            SPWeb spweb = spsite.OpenWeb();
                            tn = new TreeNode();
                            tn.Text = spweb.Title;
                            tn.Tag = spweb.Url;
                            this.tvSites.Nodes.Add(tn);
                            this.GetChildSites(spweb, tn);
                            this.tvSites.ExpandAll();
                        }
     
                    });
                 
                }
                catch { }
            }
            private void GetChildSites(SPWeb _subsite, TreeNode _tn)
            {
                foreach (SPWeb subsite in _subsite.Webs)
                {
                    tn = new TreeNode();
                    tn.Text = subsite.Title;
                    tn.Tag = subsite.Url;
                    _tn.Nodes.Add(tn);
                    this.GetChildSites(subsite, tn);
                }
     
            }
     
            //WEB SERVICE
            private void BuildSitesTreeFromService(String _url, TreeNode _tn)
            {
                WSS_Webs.Webs service = new WSS_Webs.Webs();
                service.PreAuthenticate = true;
                //service.Credentials = System.Net.CredentialCache.DefaultCredentials;
                service.Credentials = new System.Net.NetworkCredential("***", "***", "***");
                service.Url = _url + @"/_vti_bin/webs.asmx";
     
                XmlNode sites = null;
     
                try
                {
                    sites = service.GetWebCollection();
                }
                catch
                {
                    return;
                }
     
                foreach (System.Xml.XmlNode subsite in sites.ChildNodes)
                {
                    tn = new TreeNode();
                    tn.Text = subsite.Attributes["Title"].Value;
                    tn.Tag = subsite.Attributes["Url"].Value;                
                    _tn.Nodes.Add(tn);
                    BuildSitesTreeFromService(subsite.Attributes["Url"].Value, tn);
                }
     
            }
  • SharePoint (MOSS) Installation and preparation for development

    So, for the 20th time I am getting a development prepped for MOSS/WSS development. And, again, I forget how to get everything configured and installed. Hopefully this post will save some of you time in doing this.

    1. Install MOSS on Server 2008. Not straight forward. In order to get the install working you need to SlipStream the service packs for WSS and MOSS. (use command tool with the /extract command)
    2. Once MOSS is installed and you created a site collection you are ready to get the development environment ready. I recommend, Jan Tielens' Smart Part Templates.
    3. Make sure to select "SharePoint Web Part" not "Smart Part".
    4. Build the project and run the set-up.
    5. In MOSS, find "Site Collection Features" and activate your feature.
    6. If you database stuff, set trust level to full in web.config file
    7. If you like to load an .ascx file here is some code...

    WebPart code

    namespace SharePointWebPart1
    {
        public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
        {       
            private System.Web.UI.Control control = null;       
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
                control = this.Page.LoadControl(@"\WATG\MyControl.ascx");
                this.Controls.Add(control);
            }
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
                control.RenderControl(writer);
            }
        }
    }

    .Ascx Html 

    <%@ Control Language="C#" AutoEventWireup="true" Inherits="SharePointWebPart1.MyControl" %>
    <h3>This is my content</h3>

    <asp:Button ID="btnTest" runat="server" Text="click me!" /> 

    .Ascx code

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace SharePointWebPart1
    {
        public partial class MyControl : System.Web.UI.UserControl
        {
            protected Button btnTest;

            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Write("Hello");

                this.btnTest.Click += new EventHandler(btnTest_Click);
            }

            void btnTest_Click(object sender, EventArgs e)
            {
                Response.Write("Great job!");
            }
        }
    }

     

     

     

  • SSIS package fails when Package Configuration is enabled using XML

    I thought I share this with you, before you waste time like I did.

    If you are planning to deploy an SSIS with "Package Configurations" enabled using XML file, and if one of the dynamic properties is the "ConnectionString", you MUST add the "Password=xxx" yourself into the string. The Wizard won't store it.

    Good luck

     

    --tolga

  • "Full text index" optioni is grayed on database table

    Here are the steps to enable this

    1. Make sure the SQL Server FTS is running
      1. Click Start, Programs, Microsfot SQL Server 2005, Configuration Tools, SQL Server Configuration Manager
      2. Select SQL Server 2005 Services
      3. Find "SQL Server FulltextSearch"
      4. Enable/Start the service
    2. Go back to SSMS (Management Studio) and open a query window. Execute the following query...
                                    
    use [database name]

    exec sp_fulltext_database 'enable'

     

    Good luck...

  • C# Page Turn revisited - source code available this time :)

    I did get a lot of hits on my first blog about the C# version of the famous Silverlight page turn effect. Then, I didn't post the source files, simply, because I wasn' fully satisfied. The other day, I sat down again and looked at all the code and started from scratch. I took the JavaScript version and simply translated it. This time, however, I have a much deeper understanding of how Silverlight works. It was much much faster.

    Here are the links:

    View the application..

    Get Source files... 

    Good luck. I hope this will help some of your understand Silverlight 2.0 from a much deeper base.

    --tolga

  • Silverlight Pool Table

    Hi:

    I haven't really done much lately with regards to Silverlight. So, I just now uploaded a new project which I like to share with the community. It is a simply app, which I, however, intend to update regularly.

    Highlights of the apps are...

    • Drag and Drop
    • Sound integration
    • Public events and custom delegates

    The url is http://silverlight.services.live.com/invoke/86739/Pool%20Table%20v1.0/iframe.html

    The source code is availabe on codeplex under http://www.codeplex.com/PoolTable1

    --tolga

     

     

  • Web UserControls (.ascx) and validations...

    Description 

    I encountered a very odd behavior a couple of days ago, which turned out to be a very simple issue.

    A fellow developer created a .ascx for me to use in my page. I have a gridview control with an *detail* button for each row.

    This edit button is supposed to *pop-up* the user control which displays more detailed information for that particular row. For some odd reason, some postbacks of my, parent, page where suddenly disabled. One of them was the *detail* button.

    Solution

    To make a long story short, the cause for this odd behavior where validation controls on the user control. We solved the issue by explicitly setting the *ValidationGroup* properties of all validation controls and their associated user input controls.

     

  • Getting Powershell to work in your asp.net application

    First, the most important part is to add the System.Management.Automation.dll to your web application. Its location is a mystery...at least for me it was. HEre it is

    "C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0"

    Once you added this reference you are able to imports the following asseblies...

    using System.Management.Automation;

    using System.Management.Automation.Runspaces;

    Now you are able to code your powershell "HelloWorld" asp.net web application. This is one...

More Posts Next page »