0

I created custom actions from ribbon via this article - Deploying Custom Action to specific lists in SharePoint 2010 - which works fine.

But when I created a new project I copied from my last project and forgot to change path for the JS file, and deployed the project.

var scriptlink = site.UserCustomActions.Add();
scriptlink.Location = "ScriptLink";
scriptlink.ScriptSrc = "/_layouts/15/SharePointProject2/JavaScript2.js";
scriptlink.Update();

Now if I correct the path to the JS file SharePoint still tries to loads the script from the old path.

I have tried reseting IIS, but still SP gets the wrong file.

What can I do in future when I have that problem? I assume it is some cache but I don't know what delete and where.

I use SP2013 and VS 2013

0

Try this(CSOM):

static void Main(string[] args)
        {
            string siteUrl = "http://sp:12001";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;

            UserCustomActionCollection collUCA = site.UserCustomActions;
            clientContext.Load(collUCA, cas => cas.Where(ca => ca.Title == "myScript"));
            clientContext.ExecuteQuery();
            if(collUCA.Count<1){
                UserCustomAction scriptlink = collUCA.Add();
                scriptlink.Location = "ScriptLink";
                scriptlink.Title = "myScript";
                scriptlink.ScriptSrc = "/_layouts/15/js/JavaScript1.js";               
                scriptlink.Update();

                clientContext.ExecuteQuery();
            }
            else
            {
                UserCustomAction scriptlink = collUCA.First();
                scriptlink.ScriptSrc = "/_layouts/15/js/JavaScript2.js";
                scriptlink.Update();
                clientContext.ExecuteQuery();
            }



            Console.WriteLine("done");
            Console.ReadKey();
        }
  • Thanks for reply, but i deploy it as site features so with my knowledge i dont know how in this case use your code. But finally i found mistake - i can't use this same name of js functions like my another features. – Karol Kozłowski Jan 16 '18 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.