Solved

SharePoint Hidden Column

Posted on 2011-02-16
6
844 Views
Last Modified: 2012-05-11
Hi,

I'm trying to hide a column in SharePoint 2007 in a document library.  The column needs to be hidden so that users cannot update the field, but it needs to be visible in the default view.  That is the easy part and I've successfully done that.

However, my problem arises when I try to edit a document via C# code using the SharePoint dlls.  My code is as follows:

foreach (SPFile document in docLibrary.Files)
{
     string name = document.Properties["MyColumn"];
}

when the column is hidden, it is null.  However, when it's optional, it returns the default value.

How can I hide this column from users but still be able to update it in code?  Thank you!
0
Comment
Question by:88brad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Rafael I
ID: 34912077
How are you hiding the column?
0
 

Author Comment

by:88brad
ID: 34913145
Going into each content type the column is added for and selecting hidden instead of optional/required.
0
 
LVL 6

Accepted Solution

by:
Rafael I earned 250 total points
ID: 34916923
That sounds really complicated.  Why don't you try using JavaScript to hide the column(s) you don't want to be shown instead?

First you need to "edit" the page you want, in this case NewForm.aspx by adding "PageView=Shared&ToolPaneView=2" to the URL (no quotes, of course)

Then follow the directions here: http://www.sharepointkings.com/2009/10/hiding-field-in-sharepoint-through.html

Basically, you edit your NewForm.aspx and add a Content Editor Web Part, and use a JavaScript function to hide the field you want.  You should be able to see it in your code since the column is just like all the other columns now.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 3

Assisted Solution

by:Nomoho
Nomoho earned 100 total points
ID: 35025766
Hello,

About your code:
foreach (SPFile document in docLibrary.Files)
{
     string name = document.Properties["MyColumn"];
}

You want to display the content of your column or edit it?
To display it I use:
document.Item["MyColumn"] instead, I am not sure of what is containing document.Properties["MyColumn"]

To edit it,
document.Item["MyColumn"] = value;
document.Item.SystemUpdate(false); // (Or Update() if you want to raise event handlers)

Hope this may help you.
0
 

Assisted Solution

by:88brad
88brad earned 0 total points
ID: 35127967
Thanks for all your help, document.Item["MyColumn"] ended up not working either - the property didn't exist (even though it had a value on the page.

I ended up adding a property and saved it like this:

     document.Item.Properties.add("MyColumn", "VALUE");
     document.Item.Update();

After this, then I could access the property.  Not ideal, but I would just add "Default Value" if it didn't exist.  It was still hidden after this but thanks for everyone's help.
0
 

Author Closing Comment

by:88brad
ID: 35170721
Rawsteak's solution was where I was going if my solution didn't work.  Nomoho had the right idea but was missing some details.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This collection of functions covers all the normal rounding methods of just about any numeric value.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question