I've a little problem. We've a document library and in this library every subcompany can upload their documents. Now I want a column where the name of the subcompany is displayed after the document upload.

The name of the subcompany is in the Domain and in the Login Name. Is there a way to get the Name of the subcompany in this column with the calculated columns or something else?

Thanks in advance!

  • How does the name of the company look like? can you give an example? Commented Jun 12, 2013 at 9:13

2 Answers 2


Calculated columns cannot refer to people fields so not sure they are going to help you.

A workflow could split off the domain from the Created By user and add it to a Single Line of Text column?

Alternatively, could you just get whoever is uploading the document to set which company they are from using a choice field?

  • oh, I was thinking too complicated :D
    – mbauer
    Commented Jun 12, 2013 at 11:46

I diffidently agree with Dave Paylor. However it's not too complicated to get it done throw some code, all you need is an Event Receiver with the following settings supposing that you already have a library with a column of type "Single line of text" that shall hold the domain name:

  • Event type: List Item Events.
  • Event Source: The list you are working on, custom or OOTB.
  • Event handled: ItemAdded.

Here is the code to have in the CS file of the event receiver:

       SPList docLib = properties.Web.Lists.TryGetList("Name of the document library");
       SPField companyName = docLib.Fields["Name of the text field that will hold the subcompany name"];
       string subCompanyName = System.Environment.UserDomainName;
       companyName.DefaultValue = subCompanyName;

Every time a document is added to the library the domain name of the user who added the document will be inserted in the field.

Just in case you're up to add this particular text field programmatically, use below code in a feature receiver inside "event raised after a feature has been activated" block:

        SPSite rootSite = (SPSite)properties.Feature.Parent;
        SPWeb rootWeb = rootSite.RootWeb;
                SPListCollection collList = rootWeb.Lists;
                SPList docLib = collList.TryGetList("Name of the document library");
                SPFieldCollection collFields = docLib.Fields;
                SPField subCompanyName = null;
                if (collFields.ContainsField("Name of the text field that will hold the subcompany name") == false)
                    subCompanyName = new SPField(collFields, "Text", "Name of the text field that will hold the subcompany name");
                    SPView defaultView = docLib.DefaultView;
                    defaultView.ViewFields.Add("Name of the text field that will hold the subcompany name");
        catch (Exception ex)
            throw new Exception(ex.ToString());

As i said, i would recommend Dave Paylors answer upon mine as not everything should be done throug coding when you can do it in an easier way.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.