Re: Unix command-line tools to edit SharePoint site?

[email protected] ("Jack Trinh (jtrinh)")
Newsgroups perl.beginners
Message-ID <8C6B22BB8682AD4BA879161886E45E6202A7339E@xmb-sjc-218.amer.cisco.com>
SE CORRECT THEM FOR ME.
Thanks
JACK



 -----Original Message-----
From: 	[email protected] [mailto:[email protected]]
Sent:	Friday, June 13, 2008 05:15 PM Pacific Standard Time
To:	[email protected]
Subject:	Re: Unix command-line tools to edit SharePoint site?

Kelley,

I just completed a project had to figure out how to create SharePoint
calendar events from Perl.  This was quite a chore, as MS's SOAP
interface does not adhere to open standards.  As such, I had to create
my own custom SOAP requests that contained MS's CAML query language.
See the example below, and feel free to contact me, ericjhahn [at]
gmail [dot] com, if you have any other problems / questions.

# the GUID can be accessed from the GetListCollection and looks like
082CAB40-1E09-40F1-918C-29563AE9D135
use Data::Dumper;   #  this is an excellent utility for printing
hashes etc.
use LWP::UserAgent;
use HTTP::Request;
use strict;

# CREATE EVENT
my $site = '<your domain site>/sites/<your sharepoint site>';
my %fields = (
               Title => 'My New Event',
               Location => 'The Warehouse',
               Description => 'Stock some stuff',
               EventDate => '2008-06-13 09:45:45',
               EndDate => '2008-06-13 10:15:45',
             );
my $eventID = createCalendarEvent($guid, $site, \%fields);

sub createCalendarEvent {

  my $listGUID = shift;
  my $site = shift;
  my $fields = shift;
  my $batch = '<Batch OnError="Continue">
               <Method ID="1" Cmd="New">';

  while (my ($key, $value) = each (%{$fields})) {
    $batch .= '<Field Name="' . $key . '">' . $value . '</Field>';
  }

  $batch .= '<Field Name="fAllDayEvent" />
             </Method>
             </Batch>';

  my %parameters = ("listName" => $listGUID,  # calendar list
                    "updates" => $batch
                   );

  my $soap = createEnvelope("UpdateListItems",
                            "http://schemas.microsoft.com/sharepoint/
soap/",
                            \%parameters
                           );

  my $ua = new LWP::UserAgent(keep_alive => 1);
# the only authentication i could get to work was through the URL  (we
have basic auth on the sharepoint site)
  my $request = new HTTP::Request(POST => 'http://<your
username>:<your password>@' . $site . '/_vti_bin/Lists.asmx');

  $request->content_type("text/xml; charset=utf-8");
  $request->content($soap);
  $request->header(SOAPAction => '"http://schemas.microsoft.com/
sharepoint/soap/UpdateListItems"');

  my $response = $ua->request($request);

# parsing to return the event ID so that we can store it and access
this event later
  if($response->code == 200) {
    my $id = $response->as_string;
    $id = substr($id, index($id, "ows_ID"));
    $id =~ s/^.*ows_ID="//;
    $id =~ s/".*$//;
    chomp($id);
    return $id;
  }
  else {
    return 0;
  }
}  # end createCalendarEvent()


-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.