Showing posts with label Sharepoint 2007. Show all posts
Showing posts with label Sharepoint 2007. Show all posts

Sunday, October 19, 2014

Form was customized not working with attachment


Share/Save/Bookmark

Are you troubled with this error? then 99% of chance that you have done something very similar to what i did, building a custom list form(new/edit) where custom list form(dataform)  webpart is added. Also, i believe this is happen to be in only in SharePoint 2007(did not test in 2010/2013).

So when a custom list form webpart is added in the sharepoint designer, it supposed to work as is without any customizations but attachment functionality is broken as it was never completely built. MSFT has released a fix for it. There is a XSLT code snippet you need to copy from here to get this fixed, its pretty straightforward.


Subscribe

Tuesday, September 14, 2010

Ways to modify web.config

Share/Save/Bookmark


All about modifying web.config in Sharepoint environment.

Following are the different approaches that i have figured out that can possibly be used to modify web.config:

1. Rich API SPWebConfigModification
2. Declarative approach by having the changes in webconfig.*.xml
3. using ASP.net configuration
4. Modifying it as just another xml file

1. SPWebConfigModification

Sharepoint api is compiled so well that the changes that are written to web.config
can be easilty removed as well. A code sample to add the WCF/webservice entry using this API can be found here.

2.Declarative approach

When we are so used to do everything as a xml file. Ofcourse its the easiest way of
implementing things in sharepoint and so in this case.

In this approach the modifications to the web.config can be defined in a XML file
that will named as webconfig.*.xml,placed in 12\config folder.
When a  new webapplication is getting created sharepoint looks up for the files with pattern webconfig.*.xml
under 12/config and merges those changes with the web.config
Please note that this works only for new webapps and it impacts all webapps but not a specific
webapp.

To have these new changes to be included in web.config for existing webapp the following stsadm command
can be run:
stsadm -o copyappbincontent

3..Net Configuration API
All the elements/nodes and attributes of web.config are implemented as various classes and properties.
This will be a large chunk of code once you are used to SPWebConfigModification API.
Below is the code sample using Configuration class that will modify a entry in appSettings section.

public void Modify(string key, string value)
{

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");

AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");

   if (appSettingsSection != null)

   {

       appSettingsSection.Settings[key].Value = value;

       config.Save();

   }

}


4.As an xml file.
Best way to parse the xml files is to use XMLReader/XMLTextReader,XMLWriter/XMLTextWriter,XPathNavigator
but it would be a pain to write the changes as each node and attribute.
Again it depends on the requirement what to add/modify?

Sample code:

                XmlDocument document = new XmlDocument();
                document.Load(file);// file - web.config opened on FileStream

                XmlNode node = document.SelectSingleNode("/configuration");
                node.InnerXml = node.InnerXml + serviceModelChange;
                document.Save(file);

more details can be found at http://www.west-wind.com/Weblog/posts/2423.aspx


I summarize that SPWebConfigModification is the best/safe way of modifying web.config programmatically.

  Subscribe

Friday, September 10, 2010

SPWebConfigModifications throws exception all time

Share/Save/Bookmark


{Expression must evaluate to a node-set.}
{'' is an invalid expression}

Are you victim of the above error messages?
Is SPWebConfigModification throwing exceptions all the time when modifying the web.config?
And you think it should not give that message for the flawless code that you have written?
then root cause could be because of the corrupted entries in webconfigmodification collection that still persist.
So how to get rid of them?

Call SPWebApplication.WebConfigModifications.Clear() before adding the entries(SPWebApplication.WebConfigurations.Add(EntryItem))

In a very special case of mine the above call didn't succeed and i have to call
SPWebApplication.Farm.Services.GetValue().WebConfigModifications.Clear() too.

So what did we really do just now, The call SPWebApplicaiton.WebConfigModifications.Clear()
cleared the bad entries on the current webapp where we are trying to add the entries.But there
could be bad entries still existing on the other webapps because of which error might be thrown though
there is nothing wrong in your code.
So to clear out all the corrupted entries we have called SPWebApplicaiton.Farm.Services.GetValue().WebConfigModifications.Clear()
Internally this call will reload all the web.config entires and modifies the current webapp
web.config to include the new changes.


  Subscribe

Thursday, June 3, 2010

How to handle the checkedout items when modifying Sharepoint Listitems

Share/Save/Bookmark

Im sure you might not get what this post is all about by just looking at the title, so i give you with the scenario you might be into and then you can go through the complete post
scenario :
I have a requirement for a tool that should update the metadata(sitecolumns value) of the document library/list items programatically.Everything is pretty clear except about the items that are checked out, that you get when you ponder ;-)
I can get the tool in fly if i ignore the items that are checkedout. So how to deal with the checked out items?After digging into the setttings of the library i thought disabling the version settings would do the trick but i get only the error "you cannot edit the properties when the document is checked out" when trying to edit the items that are already checked out by other user
Though after using the method SPListItem.SystemUdpate() i can do nothing about the checkedout items. More strategically im left with the only option to run the tool/code untill there are no checkedout items i.e i got a scheduled timer job that will run this code/tool untill no checkedout items.
Plz let me know if there is something else that you got working.Thanks!
P.S more about SPListItem.SystemUpdate() here.

Subscribe