Solved

SharePoint Hidden Column

Posted on 2011-02-16
6
836 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
  • 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now