qablan89
qablan89

Reputation: 223

Customizing upload file functionality in SharePoint picture library

Can anyone help me ,I want to customize upload functionality in which i want to validate the uploaded image type to the picture library

where can i set my script ?? Any one can advise ???

Upvotes: 0

Views: 2148

Answers (3)

Ferdinand Prantl
Ferdinand Prantl

Reputation: 5729

You can try creating a custom list template and replace the default NewForm.aspx and EditForm.aspx pages there. These custom form templates need not contain the same user controls and buttons as in the default picture library template. You could create a Silverlight web part with rich UI to upload images, e.g. The more you want to differ the more code you'll have to write...

An OOTB solution I can think of would be a workflow that you would force every new picture to run through but it would be quite an overkill for the end-user...

Of course, if you're able to validate by using just the meta-data in ItemAdding as the others suggest, it'd be a huge time-saver.

--- Ferda

Upvotes: 0

Jignesh Rajput
Jignesh Rajput

Reputation: 3558

You might be Use ItemAdding. In ItemAdding Event Method just check extension of the Document before successfully uploaded to the Library.if unvalid document than through Error message

your code something like this :

   protected string[] ValidExtensions = new string[] { "png", "jpeg", "gif"};

   public override void ItemAdding(SPItemEventProperties properties)
    {
        string strFileExtension = Path.GetExtension(properties.AfterUrl);

        bool isValidExtension = false;

        string strValidFileTypes = string.Empty;

        using (SPWeb web = properties.OpenWeb())
        {

                foreach (string strValidExt in ValidExtensions)
                {
                    if (strFileExtension.ToLower().EndsWith(strValidExt.ToLower()))
                    {
                        isValidExtension = true;
                    }
                    strValidFileTypes += (string.IsNullOrEmpty(strValidFileTypes) ? "" : ", ") + strValidExt;
                }

      // Here i am going to check is this validate or not if not than redirect to the 
      //Error Message Page. 
                if (!isValidExtension)
                {
                    properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                    properties.RedirectUrl = properties.WebUrl + "/_layouts/error.aspx?ErrorText=" + "Only " + strValidFileTypes + " extenstions are allowed";

                }

        }

    }

Upvotes: 5

Tannheuser
Tannheuser

Reputation: 416

You could use SPItemEventReceiver for your library and add your logic into ItemUpdating() and ItemAdding() methods.

Upvotes: 0

Related Questions