Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a question on connected web parts

Status
Not open for further replies.

theprowler

Programmer
Mar 25, 2005
29
IT
Hi all,
it is possible to connect web parts on different sites ?

I'm working with a site and i'd like to create a web part in my home page that displays latest documents inserted in all subsites.

To do that i thought to create connected web parts but i don't know if it is possible to connect web parts through different sites.

Best regards,

Massimo
 
Hi Massimo,

I don't think you can do what you want with connecting webparts, in the sense that you mean. Your best option is to make a webpart that loops trough the subsites and document libarys. (make use of that object model). And maybe select your documents with the SPQuery object.

I hope this helps.

Greetings
 
Hi Chaser thanks for your reply.

That's quite a pity can not use connected web parts ! :D

I think looping through all subsites and in all doc libraries seems a good idea.

By the way, my objective is to insert in this web part links to documents inserted (in any subsite) just before or after a date inserted by the user. You know what i mean ?

What is the advantage of using SPQuery object ? Performance ?

Thanks in advance,
Massimo
 
Hi Massimo,

The SPQuery object is indeed for performance, because cheching each documents date trough code is alot of work
(for the comp ofcourse).

By the way, my objective is to insert in this web part links to documents inserted (in any subsite) just before or after a date inserted by the user. You know what i mean ?

you mean the user imputs the date and your webpart returns the documents(of anysite) that are created/edited close to that date.

Then i think u should use the SPQuery object. You do however need to use the SPQuery object agains each (sub)site in your loop.

I havent used the SPQuery object much so i don't have any sample code, but there alot of example to find an the www.

Greetings
 
Hi! I tried to make the loop in all my subsites using SPQuery: result is good but it takes about 40 seconds to find all documents !!

Any idea on a more fast loop?

Thanks in advance

Massimo


Here's the code:



private void findLatestDocuments(SPWebCollection currentWebCollection, SPQuery query)
{
try
{
//loop in all sites of the collection
for (int i = 0; i< currentWebCollection.Count; i++)
{
this.currentSite = currentWebCollection;
//loop in all lists...
for (int j = 0; j < this.currentSite.Lists.Count; j++)
{
this.currentList = this.currentSite.Lists[j];
//if list is a document library
if (this.currentList.BaseType == SPBaseType.DocumentLibrary)
{
this.currentDocLibrary = (SPDocumentLibrary)this.currentList;

//Select items using SPQuery...
this.currentListItemCollection = this.currentDocLibrary.GetItems(this.query);

//if there are no elements stop...
if ( this.currentListItemCollection.Count != 0 )
{
//now insert elements in a list...
for (int k = 0; k< this.currentListItemCollection.Count; k++)
{
//here i display items in a list... [...]
} }

}
}
//now if this site has subsites... call this function on his subsites!!
if (this.currentSite.Webs.Count != 0)
findLatestDocuments(this.currentSite.Webs, query);
}
}
catch(Exception e)
{
Response.Write(e.Message);
}


}
 
Well actually i expected this to be fast...

Are you getting alot of results? (so could it be that it takes time to load to the browser) Cos the search goes fast but rendering the output is what takes so long?!

Or only a few? (but it still spends time searching.)

Greetings.
 
Also use only the sites where the user has right to or else you webpart wont work for readers. It will also limit the amount of sites that have to be searched.

Code:
SPWeb.GetSubwebsForCurrentUser()

You could also try to make foreach loops

Code:
foreach (SPWeb myWeb in currentWebCollection){
   foreach (SPList myList in myWeb.Lists)
   {

   }
}

Greetings.
 
Hi Chaser,
yes i'm expecting a lot of results and this way to proceed is to slow for me. I've got a lot of subsites in which look for files so...
So i decided to directly execute a query on Sharepoint database.

I've created a table in another database in which i store a list of site urls (in those sites i'm looking for latest documents); then i execute this query on sharepoint database:

"select leafName, TimeLastModified, ('" + serverName + "' + DirName + '/' + leafName) as DirName from Docs inner join Webs on Webs.Id = Docs.WebId where doclibrowid is not null and timeLastModified >= " + "'" + selectedDate + "'" + " and " + siteList;

(siteList is the urls list while selectedDate is the date selected by the user; doclibrowid not null means that the element is part of a doc library)

this way i think is the most rapid i can perform now.

Cheers,

Massimo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top