This project is read-only.

set default image

Aug 2, 2011 at 5:57 PM
Edited Aug 3, 2011 at 3:39 AM

Hi Zick & all

I really love this solution! May i ask:

How can i set the default image to point to an image file(default.png) located within the project, if the user fails to select a picture to upload on creation of a SharePoint 2007 custom list item? Any ideas please? Much appreciated.

Aug 3, 2011 at 6:55 AM

Hello,

I invite you first to download this solution : http://areaprog.codeplex.com/

Normally, it is the new version of image field. I need some tests and ideas to improve it. If this solution works for you, I can try to implement what you need quickly but I first need to know if the code works on another machine that mine.

Thanks

Aug 3, 2011 at 7:02 AM

Hi ssougnez

Really? Thanks so much! will get to it now & provide u a response ASAP! :)

Aug 3, 2011 at 7:14 AM

Hi ssourgnez

I did download the file 'custom field management' but was unsuccessful in deploying it. Can i ask, if you may provide me with some code samples (if possible) to my 1st post, as im allowed to use 'ImageField' instead of 'AreaProg'. So sorry.

Will you please do me the favour?

I have @ ChoosePicture.aspx.cs of project 'ImageField':

 // Click on the upload button
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // If no file has been selected, leave the function
            if (uploader.FileBytes.Length == 0 || string.IsNullOrEmpty(uploader.FileName))
            {
                //???????????????????
                //testing!!!   
                //the following code are not accurate, as i continue to try & achieve my aim
                //set default image to custom list but not upload to pic library here

                uploader.FileContent.Equals("12/TEMPLATE/IMAGES/noimage.png");
                // Create the Bitmap from the uploaded picture
                Bitmap image = new Bitmap(uploader.FileName);

                // Get the dimension of the miniature
                Dimension dimensions = Resizer.GetMiniature(image.Width, image.Height);
   
                return;
            }


            // Granting privileges
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                Guid guid = Guid.NewGuid();

                // Picture Library
                SPPictureLibrary list;

                try
                {
                    // Retrieve a reference to the picture library
                    list = (SPPictureLibrary)Site.RootWeb.Lists["Image Picker Picture List"];
                }
                catch
                {
                    // If the library "Image Picker Picture Library" doesn't exists, create the list
                    Guid listGuid = Site.RootWeb.Lists.Add("Image Picker Picture List", SPUtility.GetLocalizedString("$Resources:ListDescription", "ImagePicker", SPContext.Current.Web.Language), SPListTemplateType.PictureLibrary);
                   
                    list = (SPPictureLibrary)Site.RootWeb.Lists[listGuid];
                    list.OnQuickLaunch = false;
                    list.Update();
                }

                // Add the picture in the library
                SPFile it = list.RootFolder.Files.Add(guid + uploader.FileName.Substring(uploader.FileName.LastIndexOf('.')), uploader.FileBytes, true);
                // Update the item
                it.Update();

                // Create the Bitmap from the uploaded picture
                Bitmap image = new Bitmap(uploader.FileContent);

                // Get the dimension of the miniature
                Dimension dimensions = Resizer.GetMiniature(image.Width, image.Height);

                // Changing the picture of the parent page
                Page.Response.Write(@"<script language='javascript'>
                                        opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').src = '" + list.ParentWeb.Site.Url + "/" + it.Url + @"';
                                        opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.visibility = 'visible';
                                        opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.width = '" + dimensions.Width + @"px';
                                        opener.document.getElementById('" + Page.Request.QueryString["GUID"] + @"').style.height = '" + dimensions.Height + @"px';
                                        opener.document.getElementById('" + Page.Request.QueryString["path"] + "').value = '" + list.ParentWeb.Site.Url + "/" + it.Url + @"'
                                        window.close();
                                      </script>");
            });
        }//end method

Aug 3, 2011 at 7:26 AM

Hello,

actually, "custom field management" is just a tool to be able to save easily properties for custom field. What you're looking for is the "Image Field" solution. The code shown above is the old version of Image Field. Normally, on the codeplex http://areaprog.codeplex.com/, I released a new version of Image field. One for SP 2007 & SPS 2010. And if I'm not wrong, there are some samples with custom field management source code, you should have a look at it ;-)

If you have some problem with the AreaProg codeplex, please open a new discussion on this codeplex ;-)

Thanks

Aug 3, 2011 at 7:42 AM

Hi ssougnez

thank you for the response & clarification. Now that i have a better understanding between the 2 projs, im going to install the new .wsp & test out the functionalities. Will seek ur expertise from you then. Hope everything turns out fine :x

Regards

Aug 3, 2011 at 9:50 AM

Hi ssougnez

I have 2 questions:

-1.  In the new Areaprog.ImageField project, can i ask u how i may set the image size to be the same for every custom list item created? I did something similar with the previous project 'ImageField' by modifying 'fldtypes_ImageField.xml to the following:

<RenderPattern Name="DisplayPattern">
      <Switch>
        <Expr>
          <Column />
        </Expr>
        <Case Value=""></Case>
        <Default>
          <HTML>
            <![CDATA[<a href="]]>
          </HTML>
          <Column />
          <HTML>
            <![CDATA[">]]>
          </HTML>
          <HTML>
            <![CDATA[<img src="]]>
          </HTML>
          <Column />
          <HTML>
            <![CDATA[" style="border:0px;height=60;width=60;" /></a>]]>
          </HTML>
        </Default>
      </Switch>
    </RenderPattern>

-2. Also, How can i set the default image to point to an image file(default.png) located within the project, if the user fails to select a picture to upload on creation of a SharePoint 2007 custom list item? Any ideas please? Much appreciated.

Aug 3, 2011 at 9:53 AM

Sorryt but can you copy/paste this question in the discussion tab of the AreaProg Codeplex ?

I will delete imagefield.codeplex.com soon so I prefer to start the discussion in the new codeplex, thanks ;-)

Aug 3, 2011 at 9:55 AM

Yes definitely. Thank you ssougnez :)