+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / check for Attachment

check for Attachment

4 posts, 0 answered
  1. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    17 Sep 2010
    Link to this post
    Hello Telerik Team
    It exists a way to get if an Icontent Contain an Attachment like pdf or else?
    I Have something like this:
    Dim cnt as IContent= News_Provider.GetContent(id)

    and i want to check if my "cnt" object ..in this case my News contains any Attachment in its body

    thank you very much
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Sep 2010
    Link to this post
    Hello Bachar Zeidan,

    IContent object has a property called Content that you can use to get the text of the object. Then you can use some REgularExpression and check for the following format ["Libraries"] GUID . Then get all stings as IContent objects and call MimeType property to see whether application/pdf will be returned.
    The second option is using  real file extensions and look for .pdf in the Content of IContent. The third option is adding such files only through metakeys of an IContent item and calling GetMetaData directly.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    17 Sep 2010
    Link to this post
    Thank you Ivan Dimitrov
    I'am working for the first option but i have another question:
    The Guid String have always the same Length ?

     

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Sep 2010
    Link to this post
    Hi Bachar Zeidan,

    You need to check for the provider name - if it is one of providers you use for Images and Documents module ( the default one is Libraries) and then to resolve the Guid which length is 36.

    Here is a sample code

    public bool ResolveValue(Control control, string val)
           {
               if (val.StartsWith("~/"))
                   return control.ResolveUrl(val);
     
               int idx = val.IndexOf("]");
     
               if (idx < 0)
               {
                   return val;
               }
     
               string provider = val.Substring(1, idx - 1);
               if(provider == "Libraries" || provider == "SomeOtherProvider")
               {
               string strId = val.Substring(idx + 1);
               Guid id = new Guid(strId);
     
               if (ContentManager.Providers.ContainsKey(provider))
               {
                   IContent cnt = ContentManager.Providers[provider].GetContent(id);
                   if (cnt != null)
                     {
                      // check mimetype here and retun true or false
                     }
               }
        }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered