Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SharePoint Hidden Column

Posted on 2011-02-16
6
Medium Priority
?
847 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 1000 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 3

Assisted Solution

by:Nomoho
Nomoho earned 400 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

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.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Viewers will learn the different options available in the Backstage view in Excel 2013.
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…

721 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