Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: to get file names and timestamps from sharepoint

by Sinistral (Monsignor)
on Mar 21, 2010 at 14:33 UTC ( [id://829950]=note: print w/replies, xml ) Need Help??


in reply to Re: to get file names and timestamps from sharepoint
in thread to get file names and timestamps from sharepoint

SharePoint is a Microsoft enterprise solution for providing collaborative space and document/artifact workflows. The fact that you've already connected via NTLM is a good first step. Since everything in SharePoint is a list, please see the links I posted in Access sharepoint calendar using LWP (which, despite the title, I provided links that do NOT use LWP.

  • Comment on Re^2: to get file names and timestamps from sharepoint

Replies are listed 'Best First'.
Re^3: to get file names and timestamps from sharepoint
by vbagavan (Initiate) on Mar 21, 2010 at 18:45 UTC
    use WWW::Mechanize; use LWP::UserAgent; use LWP::Authen::Ntlm; use Storable; use DBI; use FileMoveDMS2DStage_Parm; use LWP::Debug qw(+); my $URL_Parm_DMS="https://sharepoint.com"; &Parm_file::InitEnv();#parameter file for credentials# $mech = WWW::Mechanize->new(autocheck=>1,keep_alive=>1); $mech->agent_alias( 'Windows IE 6' ); $mech->credentials("sharepoint.com:443",'',$ENV{'UserId_Parm_DMS'}, $E +NV{'Password_Parm_DMS'}); $mech->get($URL_Parm_DMS); my $html = $mech->content; @names = qw(file1); # COUNTS EACH ELEMENT OF THE ARRAY $n = 0; $mech->get($urlFile); $mech->save_content($filename);
    I have tried with this code to connect. But if i get the file name from share point my work is very easy. But some how i am not able to get idea to know the file name. I would really appreciate he you guys could help me on this.

    20100409 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

      First off, please edit your code so that the Perl code is between <code> and </code> tags.

      Then please explain what you are asking for. Your code seems to connect to SharePoint as if it were a web browser and tries to download files from a particular page. Is that correct? I'm guessing that when you use Internet Explorer and use your credentials for accessing the SharePoint site you see a paticularlist of files. What happens when you run your script? Are there any debugging messages? I also don't see the ever popular

      use strict; use warnings;

      which helps identify many problems with Perl code. Did you write this code, or simply copy it from example without understanding what it is trying to do?

        Thanks!! Below code is working fine to move the files from sharepoint to local directory if know the file names.(@names). But now I have the new requirement to move the files to local directory without knowing the file names. These file names also needs to get from the html code. My idea is to put sharepoint content into html. Search for current date in html and take the file name before that date and put into a variable and then check that file date and name in existing table if it is newer file and date then move the file. I am asking you guys how to get the file names...
        #!/usr/bin/perl -w use WWW::Mechanize; use LWP::UserAgent; use LWP::Authen::Ntlm; use Storable; use DBI; use Parm_file; use LWP::Debug qw(+); my $URL_Parm="https://sharepoint.com"; &Parm_file::InitEnv();#parameter file for credentials# $mech = WWW::Mechanize->new(autocheck=>1,keep_alive=>1); $mech->agent_alias( 'Windows IE 6' ); $mech->credentials("sharepoint.com:443",'',$ENV{'UserId_Parm'}, $ENV{' +Password_Parm'}); $mech->get($URL_Parm); my $html = $mech->content; @names = qw(file1 file2 file3); # COUNTS EACH ELEMENT OF THE ARRAY $n = 0; while ($names[$n]) { print "\n"; print "Searching for $names[$n].xls;\n"; my $startPos = index($html,">$names[$n]<img"); if ($startPos > 0) { my $startPos1 = index($html,"<NOBR>",$startPos); my $endPos = index($html,"</NOBR>",$startPos1); my $filedateOn= substr($html,$startPos1+6,$endPos-$startPos1-6); my $sth; my $rows; #Connecting to the database with the credentials my $dbh= DBI->connect("DBI:ODBC:$ENV{'DSN_Parm_DB'}","$ENV{'UserId_Par +m_DB'}","$ENV{'Password_Parm_DB'}"); my $sqlStatement= "SELECT FILE_DATE FROM (SELECT MAX(FILE_DATE)FILE_DA +TE FROM Table WHERE FILE_NAME='$names[$n]')A WHERE A.FILE_DATE < '$fi +ledateOn' "; $sth = $dbh->prepare($sqlStatement); $sth->execute(); my @row = $sth->fetchrow_array; if ($sth->rows eq 0) { print "file $names[$n].xls exists\n"; print "so file is not going to move this time\n"; } else { print "Lets get move the file now.\n"; my $urlFile = "https://sharepoint.com/$names[$n].xls"; $mech->get($urlFile); $filename="$ENV{'FilePath'}$names[$n].xls"; $mech->save_content($filename); print "\n"; print "file $names[$n].xls was moved to $ENV{'FilePath_Parm'}\n"; my $sqlStatement= "INSERT INTO [Table] ([FILE_NAME],[FILE_DATE],[STATU +S],[MESSAGE])VALUES('$names[$n]','$filedateOn','SUCCESS','File transf +er has been completed') "; $sth = $dbh->prepare($sqlStatement); $sth->execute(); print "\n"; print "Record has been inserted in table with file name and date time\ +n"; } } $n++; }
      But some how i am not able to get idea to know the file name. I would really appreciate he you guys could help me on this.

      Um, read the sharepoint documentation

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://829950]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found