locked
targetFilePath must be a server relative URL RRS feed

  • Question

  • Hi,

    I am trying to add a wikipage in one of my wiki libraries  but I get "the targetFilePath must be a server relative URL" error

                   using (SPSite site = new SPSite("http://server"))
                    {
                        SPWeb rootWeb = site.RootWeb;
                        SPList wiki = rootWeb.Lists["Destination"];
                        SPFolder rootFolder = wiki.RootFolder;
                        SPFile wikiPage = rootFolder.Files.Add(String.Format("{0}/{1}", rootFolder, "MyWikiPage.aspx"),  SPTemplateFileType.WikiPage);
                        SPListItem wikiItem = wikiPage.Item; wikiItem[SPBuiltInFieldId.WikiField] = "My Wiki Page with [[wiki link]]";
                        wikiItem.UpdateOverwriteVersion();
                    }

    Could you tell me what I am doing wrong? please help!!

    Friday, June 3, 2011 4:00 PM

Answers

  • Hi,

    Thanks to share your post.

    For the issue, the method you have post rootWeb.Lists["Destination"], what is the definition of “destination”? Please check it. I think this should be the cause.

    Hope this could help you!

    Leo

    • Marked as answer by SPKabethy Tuesday, June 7, 2011 10:51 AM
    Tuesday, June 7, 2011 6:36 AM
  • In relity Destination is any wiki library I tried with different ones but finally I got it right I hope someone else find this post useful because I wasted a lot of time doing this and it is very simple

    So here the solution to create a wiki page and add customized content in it

                          SPList wiki = web.Lists.TryGetList("Customized");
                            SPFolder rootFolder = wiki.RootFolder;
                            SPFile wikiPage = rootFolder.Files.Add(String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "MyWiki.aspx"), SPTemplateFileType.WikiPage);
                            string customizedContent = System.IO.File.ReadAllText("WikiContent.txt");
                                               
                            SPListItem wikiItem = wikiPage.Item; wikiItem[SPBuiltInFieldId.WikiField] = customizedContent;
                            wikiItem.UpdateOverwriteVersion();  

    The important part is

    rootFolder.ServerRelativeUrl otherwise the code breaks

     

    Thanks for reading my post anyway =)

    • Marked as answer by Leoyi Sun Tuesday, June 7, 2011 10:52 AM
    Tuesday, June 7, 2011 10:49 AM

All replies

  • Hi,

    Thanks to share your post.

    For the issue, the method you have post rootWeb.Lists["Destination"], what is the definition of “destination”? Please check it. I think this should be the cause.

    Hope this could help you!

    Leo

    • Marked as answer by SPKabethy Tuesday, June 7, 2011 10:51 AM
    Tuesday, June 7, 2011 6:36 AM
  • In relity Destination is any wiki library I tried with different ones but finally I got it right I hope someone else find this post useful because I wasted a lot of time doing this and it is very simple

    So here the solution to create a wiki page and add customized content in it

                          SPList wiki = web.Lists.TryGetList("Customized");
                            SPFolder rootFolder = wiki.RootFolder;
                            SPFile wikiPage = rootFolder.Files.Add(String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "MyWiki.aspx"), SPTemplateFileType.WikiPage);
                            string customizedContent = System.IO.File.ReadAllText("WikiContent.txt");
                                               
                            SPListItem wikiItem = wikiPage.Item; wikiItem[SPBuiltInFieldId.WikiField] = customizedContent;
                            wikiItem.UpdateOverwriteVersion();  

    The important part is

    rootFolder.ServerRelativeUrl otherwise the code breaks

     

    Thanks for reading my post anyway =)

    • Marked as answer by Leoyi Sun Tuesday, June 7, 2011 10:52 AM
    Tuesday, June 7, 2011 10:49 AM