5

I have the following code which creates an item in the library I want:

string newPageXml = String.Format(@"<Batch OnError='Continue'>
                        <Method ID='1' Cmd='New'>
                            <Field Name='ID'>New</Field>
                            <Field Name='Title'>{0}</Field>
                            <Field Name='PublishingPageContent'>{1}</Field>
                            <Field Name='LinkFilenameNoMenu'>{2}</Field>
                        </Method>
                    </Batch>", "test.aspx",
                             Microsoft.SharePoint.Utilities.SPEncode.HtmlEncode(newPageContent),
                             "test.aspx");

XmlDocument xdPage = new XmlDocument();
xdPage.LoadXml(newPageXml);
newItem = xdPage.DocumentElement;
createdItem = ceoList.UpdateListItems("Pages", newItem);

But when the item is created it gets the ID for that item as the file name. So if the ID is 37 then the Name will be 37_.

I've tried DisplayName, LinkFilename, Name and a few other values but the ID always shows up at the name. What do I need to put in here to specify the file name?

If I can't use the list service, how can I use any of the web services to create a new item in the Pages library?

5
  • Is there anyone out there? I've been banging my head against this seemingly simple problem for two days now and I'm about to loose it! Jul 19, 2012 at 17:34
  • Have you tried "BaseName" ? or "URL" ? Jul 20, 2012 at 13:27
  • I am not sure for MOSS, but you can try "FileLeafRef" for File name. May be it can help !
    – J.Shah
    Jul 24, 2012 at 11:25
  • @abe Did you get this working?
    – Amicable
    Jul 27, 2012 at 8:07
  • Yes, I ended up using a combination of the copy and list service to get a complete solution. I'll post what I did any why I needed both for posterity. Jul 27, 2012 at 15:03

2 Answers 2

3
+50

Lists.asmx is the wrong service to use. My head banging into the subject suggested that there are 3 ways to upload to Sharepoint:

  1. Copy.asmx web service
  2. WebDav
  3. Frontpage Rpc (Remote Control Procedures)

To summarise the first two are limited by Windows to file sizes around 2MB for reliable transmission (higher and you can get OutOfMemoryExceptions). This is because Windows must allocate byte arrays in continuous memory. Larger files need to be sent in fragments, which only RPC supports.

Also important to note, WebDav can't send MetaData at all (without support from web services) so it will be displayed as the default content type. If there are more than one content types, it will also remain checked out and invisible to users.

The RPC method Requires Frontpage Extension are installed on the Sharepoint server, which are shipped with Windows Server you just need to install the Windows Component.

This article was the best I could find off hand - it has examples for all three.

Some other articles:

Helper class for using Copy.asmx

Part 2: Helper class for RPC

Edit: FrontPage RPC with better explanation

1
  • 1
    Had the same problem, Frontpage RPC is not the best documented way, but it works and let's you specify pretty much everything you want. I'd recommend it too.
    – Jasper
    Jul 23, 2012 at 8:32
0

I think for a publishing page you need to actually upload a "file" even though it isn't really a file as such. You can use the copy.asmx operation to take an existing page and set pretty much all the properties to create a new page - would that work?

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ca1b0312-c6d9-4ceb-a1dd-6909b458157b

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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