in

SharePoint University

Clean slate. Nothing but SharePoint.
Go, SharePoint!

Add Item Via Web Service

Last post 03-02-2008 8:36 AM by UserSP. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 02-25-2008 11:24 AM

    Add Item Via Web Service

    Hey guys,

      This has been bugging me for weeks, so it would be amazing if someone could help me out. I would like to add a wiki page programmatically via the web services. I can do this via the Object Model API, but I won't have access to the SharePoint server,so I have to rely on web services. Does anyone know how I can go about doing this? I assume I'll have to dabble in XML but if there's a template for it or something, that would be great.

    Thanks for any help!

  • 02-25-2008 4:31 PM In reply to

    Re: Add Item Via Web Service

    You can use the web services as you said and as a Library is really just a special list, I believe it's the lists.asmx web services that you need to look into. What are you trying to create exactly, if I may ask?

    Filed under:
  • 02-26-2008 5:24 AM In reply to

    Re: Add Item Via Web Service

    Hi, thanks for the reply. I have a winform and want to take the text entered in a textbox and post it as a new wiki page (within a constant document library called WIKI). I've been able to do this via the object model, but it proves a lot more tricky via web services. Using lists.asmx, I am able to retrieve information such as what pages are already present, how many there are etc...., but I'm not sure how to go about actually posting a new page. Effectively, the user clicks a button on the winform, the application then calls a SP web service (lists.asmx) and a new wiki page is created with the text from the textbox. It's the process of creating a new wiki page via lists.asmx that is stopping me.

     

  • 02-26-2008 7:04 AM In reply to

    Re: Add Item Via Web Service

    This is exactly where my problems began and still are; I keep getting distracted doing other things. As I found out, this is the difficult part until you get the list/library schema worked out. You will probably have to create the Wiki page within your application, with the formatting and etc. then check it into the your library using the UpdateListItems method of the lists.asmx.

    This site referenced a very useful utility: SharePoint XML Viewer. With this, you should be able to see the schema for use with this method and once this is worked out, it is just a matter of feeding the XML to the UpdateListItems method. The XML format of adding an item is something similar to:

    <Method ID="1" Cmd="New>
         <FieldName="ID">New</Field>
         <FieldName="Title">My wiki page title field</Field>
         <FieldName="_x00??_omments">My wiki page comments field</Field>
         ....
    </Method>

    In your case, it may well be a lot simpler as you will only have transform the data that is entered into your application so it may be just a matter of hardcoding the mappings.

    In my case, I have an SQL DataSource but I have worked out the XML transforms for the data but I have not gotten around to successfully getting VB.NET to transform this data and throw it into the list. I have coded in VB.NET in the past (about 3 years ago) but this is my first time dabbling in its SQL/XML aspects and I have no idea how to force the transform to be executed and returned in a manner to feed to the list.

  • 02-26-2008 9:26 AM In reply to

    Re: Add Item Via Web Service

    Thanks a lot, I think that's exactly what I need but the link is down at the moment, but I found this site (opens in new window), whic has another XML utility. It  has a ListXML generator which you may find useful. I'll give the tool a go (once the site is back up) and see if I can use it get my program up and running.

    For your query, could you not create an object that will take the information from the SQL DataSource and parse the information into public variables. Then from your app, call this class and access each variable (like Title, Message etc..) and then do what I'm trying to do in my program (i.e. by hard coding it). This assumes that you'll only be getting one page at a time, I guess. I've never used VB .NET, only C# so I'm not sure how feasible it is. I'll let you know if I can get my program working and will post any information that might help you on how it went.

    Thanks again for your help.

    EDIT: Just realised the blog from the original link states that all the utilities have been moved to the site I linked and that the XML viewer is in the SharePoint Utilities file.

    Filed under: , , , ,
  • 02-26-2008 9:45 PM In reply to

    Re: Add Item Via Web Service

    Unless I misunderstood, you're trying to feed into an existing document library. The ListXML generator creates list definitions XML so that you can create a custom list. Having said, I just noticed your edit and the XML Viewer is the one that you're after.

    I'm hesitating to do mine as a hardcoded exercise as that will mean X amount of queries for the data as opposed to just 1. The last thing I want to do is clog up the network and also unnecessarily force the SQL server to run queries. A single query will return all the needed data but the data has to be transformed to fit into the list.

    Well, as always, feed-back is good and I am getting an eyeful of VB.NET and C# right now but I am refraining from coding in C# for the sake of maintainability by others here.

    Filed under: , ,
  • 02-27-2008 4:51 PM In reply to

    Re: Add Item Via Web Service

    I haven't had much time to  test the tool, but from my quick test, I'm not quite sure what I'm looking for. I typed in the following info:

    Site: http://myserver/Documents/

     List Name: WIKI

    View: I left this blank. I'm not sure what goes here/where to get the information from.

    I clicked on list data and list items (one after the other) and clicked on "Get XML" . However, I'm not sure how I'm supposed to use that data with UpdateListItems. I couldn't find any XML that I could take and replace the current text with. Any ideas where I'm going wrong?

    Thanks.

    PS. Have you considered using LINQ for your XML? Not sure if it's something you'd want, but this might be interesting.

     

  • 02-28-2008 3:43 AM In reply to

    Re: Add Item Via Web Service

    The tool will give you the field (or column depending on what you're dealing with) names based on the list you are dealing with.

    For example, if your list has the following columns:

    • Name (which is just the Title field renamed)
    • Telephone (a new text field)
    • Address (a new text field)

    When you want to create a new item to store to this list, you'll find that in the XML code, your field names will be Title, x0051_ephone and x0051_ddress (see my previous XML example). That tool will help you to identify the field names so that your XML will work.

    As for LINQ, I considered it initially but decided against it. I can't remember why but I did. Maybe I will take a second look...though I might just have to look again.

    Filed under: , ,
  • 02-28-2008 3:38 PM In reply to

    Re: Add Item Via Web Service

    Ah, it makes sense now! I managed to get it to post *something* lol. I can seem to be able to write the contents and such fine, but I can't seem to name the file. I've tried all field names but with no success. The file keeps being posted with it's internal filename (i.e. 201.000, then 202.000). It's always in increment. Ive tried using ows_LinkFilename, Name, Title, ows_Title and anything along those lines with to no avail. The XML viewer has "LinkFilename", but that doesn't work either, it still comes up with numbers. Any ideas as to why this is happening? Other than that, the text (WikiField) works fine.

  • 02-29-2008 5:38 AM In reply to

    Re: Add Item Via Web Service

     

    On my travels, I also foud this site, which you may find useful. It has field titles for most document types.

    http://www.wssdemo.com/Pages/Lists.aspx

    Although this helps me confirm that a 'Title' field does exist, it still doesn't work leading me to believe that there must be more information I need to add in order to get the link working.

  • 02-29-2008 7:03 AM In reply to

    Re: Add Item Via Web Service

    Remember one of your prior questions asking about the views? This is where that comes in. Create a view for your document library that includes the filename, title and all other relevant fields; I'm guessing right now the default view is of the order or similar:

    <icon> <title> <comments <date modfied> ....

    Create a new view with:

    <icon> <filename> <title>....

    This way when you retrieve the xml, using XMLViewer, in the new view, it should identify the field for the filename. All you have to do is modify your code to enter the filename field and everything should be heading your way. To even get the data to hit the list took me a while till I discovered that tool so you're not too far off with the filenames, just have to find that field name.

    I've setup a W2K3 VM on my laptop to play around with WSS 3.0 while I'm not at work but I miscalculated the space requirements for the VM's root drive as it's capped at 10GB. Oh well...guess it's a resize and move of the virutal disk and then I'll go on from there.

    By the way that is an interesting site, I like those filters on the side but I'm surprised it says loading before it loads as there's not too many items.

  • 03-02-2008 8:36 AM In reply to

    Re: Add Item Via Web Service

    I think this may be a bug because I've checked the field names and everything runs fine but it still comes up with 220_.000, 221_.000 etc... I tried making up a field like <Field Name='ThisDoesntExist'>TEST</Field> and an error was thrown when trying to write to the site. This means that although the fields I am entering exist and are correct, it's not being processed. I'm not sure if this is specific to a wiki page, because the Tasks and Contacts page work fine. I think it might either be a bug, or it may be a case of a Wiki page requiring more information. I've tried inputting all the information for every field I get using the XML viewer but it still doesn't work. Quite strange. Hmm 

     

Page 1 of 1 (12 items)

Need SharePoint Training? Attend a SharePoint Bootcamp!
Forum content (c) original posters. Everything else (c) 2008 SharePoint Experts, Inc.