At work they wanted a global document library to upload Resumes that would link to users profiles. For the first part I created a ListViewByQuery User Control, however you can do this in a WebPart incredibly easy. What you want to do is add the ListViewByQuery in markup or create a new object like so:
Web User Control:
<SharePoint:ListViewByQuery ID="YourID" runat="server" />
private ListViewByQuery YourID; //add this where you would normally add global fields
WebPart:
protected ovverride void CreateChildControls()
{
ListViewByQuery YourID= new ListViewByQuery();
this.Controls.add(YourID);
}
Next you want to add a query and a list to the control somehow. You can either use the PageLoad event or the RenderControl Event depending on if you are using a UserControl or a WebPart:
Web User Control:
private void Page_Load(Object sender, EventArgs e)
{
SPWeb Web = SPContext.Current.Web.ParentWeb.ParentWeb; //pass in the web where your library is located
SPList List = Web.Lists["YourList"]; //this is where you pass in your list name
SPQuery Query = new SPQuery(List.DefaultView); //this is where you pass in the view you want to show on the ListViewByQuery
Query.Query = "a CAML Query"; //may want to make life easier and use the U2U CAML Query Builder if you are not
Query.ViewFields = "<FieldRefName="Field1"/><FieldRefName="Field2" /> //these are the document library fields you want to show in the view
YourID.List = List; //this is where you want to add the list to your control
YourID.Query = Query; //this is where you want to add the query to your control
}
WebPart:
public override void RenderControl(HTMLTextWriter writer)
{
SPWeb Web = SPContext.Current.Web.ParentWeb.ParentWeb; //pass in the web where your library is located
SPList List = Web.Lists["YourList"]; //this is where you pass in your list name
SPQuery Query = new SPQuery(List.DefaultView); //this is where you pass in the view you want to show on the ListViewByQuery
Query.Query = "a CAML Query"; //may want to make life easier and use the U2U CAML Query Builder if you are not
Query.ViewFields = "<FieldRefName="Field1"/><FieldRefName="Field2" /> //these are the document library fields you want to show in the view
YourID.List = List; //this is where you want to add the list to your control
YourID.Query = Query; //this is where you want to add the query to your control
YourID.RenderControls(writer); //this is where you render the control in the webpart
}
Note: There is really only one line of code difference between what you add to the Page_Load in a web user control versus what you add to a RenderControl. A WebPart may not be easier to use, but it may load faster. It really depends on if you are using the SMARTPart versus if you were to add the control straight onto an ASP .Net Page and other factors. Weigh the pros and cons and then decide which one you want to use. Also, remember to play with your strengths and use what is the most comfortable for you.
Some Nuances...
No I did not forget about my title. I had some issues when I was developing with this control, because we needed a folder for each two letter office code. When you leave the folder in the view and you do a query using the FileLeafRef it shows the folder and not the items beneath the folder. The folder has a nasty URL that does not work attached to the link. Here is what I did to get around this issue:
- In the document library click on "Modify this View" for the view that you are attaching to this Query
- Scroll down to the "Folders" Section and click the plus sign to expand the area
- Click on the radio button next to the option that tells you "Do not show folders..."
Note: Folders will no longer show in this view, which allows you to do a query based on the folder URL. This part looks a little crazy, but it works. - Go back into your code and create something that looks a little bit like so above your SPQuery:
SPFolder Folder = Web.GetFolder(LibraryName+"/"+FolderName);
This will get the folder you need. - In the Query.Query do a little something like this:
Query.Query = "<where><BeginsWith><FIeldRef Name='FileLeafRef'/><Value Type='Lookup'>"+Folder.Url"</Value></BeginsWith></where>";
So if you look FileLeafRef is the full url for your file name, so it checks if the url has the folder url in the beginning and returns all the items with that folder url in the beginning. I know it's a little nutty, but it does the job.
So that is basically how you would use an SPLIstByQuery Control and workaround the folder bug that I described. If anyone has any questions I am more than happy to assist you if I can or I can try to find an answer with my mad searching skills. I am hoping that sometime by the end of the week I will have some sample code on the next piece of this project. I am working with a List Definition for the Document Library and some item event receivers, so that when super users upload a person's resume they can attach it to their MOSS Profile. I would say I love this project more so than the past projects, but I say that every new project. I'll catch you guys later.
I was playing with the ItemUpdated Event in a Document Library Definition File using VSEWSS. I stepped into the filed like a good little girl using the w3wp.exe process. Guess what the ServerContext is null, so I can't use the UserProfileManager...I found this little MSDN Post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3273163&SiteID=1. It turns out there is a bug in the ServerContext, which is a little bizarre considering you can do SPContext.Current.Web/Site...I guess it's time to use the webservice to update user profiles: http://msdn.microsoft.com/en-us/library/ms544240.aspx. You have to love the random bugs:) Sometimes I wonder if MOSSLover is a appropriate...Maybe I should be the SharePoint Bug Girl Mascot...
I am by no means a world traveler like Joel Oleson. My goal in life is to hit as many countries as I can and try hit every single state in the U.S. So when I saw this add for the Hartford Code Camp (http://www.ctdotnet.com/) I signed up. I have never been to New England (that I can remember) in my adult lifetime. I know that in my entire life I have never seen Rhode Island, Massachussetts, New Hampshire, or Maine. So I made a decision this week that I am going to come in on Thursday in the afternoon to Hartford and drive to Providence, RI. I am going to drive all the way up I-95 to Portland, Maine. I am not going to plan much, including lodgings and where I want to go. If I see something cool along the way I am going to stop and check it out. According to Rob Foster it looks like in Portland, Maine I need to have a lobster. When the code camp finally roles around on Saturday I should have some really neat pictures and some great blog posts in August. If anyone has been following my twitter or blog you will notice that at the end of July I will be in Seattle, then I am going to New England for my roadtrip/code camp adventure and the end of the month in August I will be in New York City for a friend's wedding. If you live in any of these places let me know and maybe I can make a side detour who knows. All I know is that I have been kicking myself since my high school graduation for not hitting all these states. I am really excited, because a lot of people say August is a really pretty time to visit New England. I really can't wait to go. I think if I could I would pack my bags tommorow and head out like Forest Gump I love traveling to new places so much. Anyway, I better get back to book things and such I'll catch you guys later have a good day as always.
Something interesting came up at work recently related to people changing there name due to some form of life event. I never had really researched what would happen if someone changed there name. I really did not know if there was a GUID in AD, so I spoke with one of our network guys. He said that there is a GUID tied to every AD account, so when the name is changed in AD the information does not need to be changed only the name and account name. I wondered if this worked similarly in SharePoint. It looks like all you need to do is run a profile synchronization and the old username syncs to the new username based on the AD GUID (ADGuid property). I am not so sure how well this works with WSS 3.0. If anyone knows add a comment. I hope this helps someone understand profile imports and syncing with AD in SharePoint.
I am by no means a search guru, but at work they have tasked me with creating custom search scopes. What they want is the ability to search a bunch of document libraries of a specific name in bunch of office sites. John Ferringer gave me this awesome link:
http://blogs.microsoft.co.il/blogs/adir_ron/archive/2007/05/10/Search-Hacks-_2300_1-_2D00_-Define-Scopes-by-MOSS-Metadata.aspx. I figured that I could somehow use it to create custom scopes for the document libraries. I started playing around and figured out that I could use the main site that the office sites sit under to create a scope to only search documents. I started out by creating a scope called
"Office Documents", then I created two rules: one rule where the
Scope Rule Type = Web Address and
Web Address = "Insert Main Address" and
Behavior=Require and another rule where
Scope=Property Query and
Property Query = (drop down) contentclass=STS_ListItem_DocumentLibrary and
Behavior=Required. For that query I get a search for all documents underneath that site. Now I want to narrow the properties down to search specific document libraries, such as resumes...I cannot figure out what the custom property is for the document library name. I believe that I could use the
Property Query and somehow choose in the drop down whatever the name of the property for the document library title, then I could type in the name of the document library. After that I want to figure out how you could choose this scope, then narrow it down by specific office sites. If anyone has any ideas you are more then welcome to submit them. If not, I will continue to play around with scoping, because I have not really played around with it much in 2007, only 2003. If I have time I am going to post more on my findings, however due to the book needing to get done around September or so I will be putting that above anything.
A friend of mine made a blog post about the lack of conferences in Kansas City. Here is the post: http://www.codebucket.org/archive/2008/06/26/kansas-city-here-we-come.aspx. If you don't know Lee Brandt you need to know him, even if he's not necessarily a full on SharePoint Nation Inductee he's a great developer. He was one of my awesome teammates at Coders 4 Charity. I would like to call him one of my friends in Kansas City. He makes some good points. I also ended up in a conversation with Jeff Julian a bit later and he also makes some good points. If you want to hold a conference you need more user group attendees. For our .Net User Group it looks like we are getting between 50 and 60 people. Our Kansas City Office Geeks (SharePoint User Group), however is getting about 13 people so far at the last meeting. I am hoping that the next meeting on Windows Workflow Foundation will have over 20 people. We have 54 people signed up on our user group list. We are not going to have a conference here if we are not going to be able to pull the numbers. If you guys want a conference, then you need to start supporting your local user groups in Kansas City. I love this community. I love the people. We just need more of you to come out and show up. I know you are out there and I want to meet you and hear from you. I would love to hear more feedback from Kansas City people on why you are not coming out. Fill out the contact form. E-mail me, Twitter me...I can't answer during work hours, but I will answer by the end of the night. I hope to hear from you all.
I was using STSDev to deploy a feature that would create a custom timer job and write SharePoint Usage Data to a webservice. Somehow the feature was deployed, but never actually hit my site collection feature list. When I tried to retract the solution is said that there was a job pending that would not allow me to retract the solution package. After running stsadm -o enumdeployments I found the job id copied the id and ran stsadm -o canceldeployment <job id>. This pushed the solution into the timer jobs and I was able to delete the timer job that was stuck. Then I ran a retractsolution and deploysolution in STSDev. I guess you can say I pulled something back from the dead or the lost. Kind of like in those tv shows where you see someone caught in between two worlds in a sort of limbo. As usual I hope that someone can benefit from my experiences somehow. Have a good fourth!
I swear a good day lasts forever. This day lasted a long time. Let alone this week was pretty good too. First off this unrelated, but I have an MSDN Premium Subscription with Team Systems, so I can finally develop at home without any issues. How awesome is that? I can do what I love to do for fun without have to use trial copies and uninstalling and reinstalling programs. It gets so annoying after a while. I am so excited, because I can finally do the real playing that I want do with Server 2008 and SharePoint. Anyway, so you probably wanted to see the stuff about the Regional SharePoint Conference...
I sort of met Bob Fox on Friday night. I thought it was him and my suspicions were confirmed on Saturday morning. He comes up to me and says "I know you" in this real sarcastic tone...Dude's a real interesting guy. He reminds me a lot of my Uncle Harvey. Who is a real joker and likes to mess with people. He's can be a very sarcastic guy too. It makes me feel a little better about my speaking experiences knowing that he gets pretty nervous when he goes out and speaks with people. I feel bad that I missed his session, but I debated long and hard about his session vs. Paul Galvin's Session. I am glad that I went to Paul's session, because he talked about creating custom actions in SharePoint Designer and provisioning sites. I thought it was cool how he started up this workflow in SharePoint using a list and then showed us how to create it with Visual Studio and SharePoint Designer. He has a CodePlex Project out there with some samples that I really want to play with when my MSDN goodies arrive. Jumping back a notch I met some really great people setting up...Gary Vaughn, who is in charge of the whole event. He's a really nice guy. He seems like one of those wise sages who has been around the IT Field for a while and can teach a lot to people around himself. I also met two very cool people. They remind me of some of my parents friends who I really like. There names are Janice and Harold Brangman. I spent a lot of time with Janice. She's a very outspoken, but very cool person. I usually try to hang out with people I am most comfortable, so Paul Galvin and Janice Brangman kind of felt like people I wanted to hang out with. Paul, though, reminds me of a lot of my friends back home. He's very cool and liberal and laid back. We spent about 3 or 4 hours just sitting around chatting about everything from cats picking up mice and killing them to New Jersey, Cape Cod, and St. Louis. I guess you follow someone's blog and there Twitter sometimes you just get a feel for that person. I predict that Paul will be an MVP the next cycle. At least I'm hoping. He is the most deserving person I have ever met in my entire life (well him and John Ferringer). Ok so other than Paul Galvin, Bob Fox, and the Brangman's I also met Rachel Appell, Wes Bryan, and a bunch of other people (I am sorry I don't remember everyone's name). Everyone I met was really cool and really great. I have not met anyone I really disliked so far. I wish that I felt less like a zombie today and was cooler. I felt like one calorie of myself, because this bed was a little on the hard side. I was fueled with a lot of caffeine and awesome people. I am glad I got to talk to Wes Bryan at Bamboo Solutions a bit about alerts and the guy who did the Disaster Recovery Presentation from AvePoint, Tony Lanni. I'm really exhausted and I bet you get the jist of the awesomeness of this conference, so I think it's time for me to pass out...No I really don't think it will matter what the bed quality is when I am this tired, so my sleep should rock...
If you are in D.C. for the SharePoint Regional Conference this week as of 4 pm I should be in town. I am pretty excited, because this is my first technical conference as a speaker and attendee. If anyone is interested in meeting up I will be staying at the Holiday Inn Dulles, so just send me a direct message on Twitter. If anyone wants to chat about the MOSS Comic I'm all ears for ideas or anything else. I am taking submissions. So far I am going to re-work the first comic when I get my new drawing tablet at the end of the week and Rob Foster has submitted a second idea that I will be using. If you are not going to be in D.C. and you have an idea send your idea via the contact form on my blog. I'll catch you guys later.
One of my fellow Coders 4 Charity Groupmates, Lee Brandt, will be speaking about Test Driven Development using C# tonight. If you are in town you must come. If you are not in town and you want to come. Well hop on a flight? Anyway, here is the official information *commenses brainwashing tactics*:
Topic: TDD Using C#
Test-Driven development is a methodology that can help developers write solid, well-designed code. Very few developers practice it because very few understand how it works and how to make it work for them. We will discuss what TDD is, why developers would want to use it, and the basics of how to actually do it using Visual Studio 2008, MS Test and C# 3.0. Come find out what Red, Green, Refactor is all about and why you should care.
Presented by: Lee Brandt
Lee is a .NET Solutions Architect for Examinetics, Inc. int Overland Park, Kansas. Lee has been programming professionally for over 10 years and developing solutions in .NET and C# since the early beta releases in 2000. He is an advocate for test-driven development, design patterns and agile methodologies. Lee spends most of his free time reading about programming, discussing programming and actually writing code. Any time leftover is spent with his wife Stacey and their dog Frieda.
So you want to come now right? Can't say I didn't try...See you there:)