Solved

SharePoint Hidden Column

Posted on 2011-02-16
6
838 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sharrepoint 2010 DB size 2 33
multidimensional array 4 35
Passing a TempVar to a Combo box form 3 84
Working with SharePoint Data 8 47
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
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 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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now