I'm trying to create new columns in a Document Library that I have created (C#)

after that, I want to upload a document (from my hard disc) and later I wish to add information (as metadata) in the new columns, but I'm having troubles with this last part.

I create succesfully the columns, I upload the file succesfully too but I can't add information since this level to the recent created columns in the Document Library.

I suppose that I should specify the Document Library to use for this columns particularly, but I don't know how to do that, or maybe I'm making the insertion of this metadata incorrectly.

The error is the next: "ArgumentException", "the value is not within the awaited interval" (sorry for the translation)

Regards and I thanks for your help!

using Microsoft.SharePoint;
using System.IO;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class HowTo_SubirArchivo4 : System.Web.UI.Page
protected void Button1_Click(object sender, EventArgs e)
using (SPSite objSitio = new SPSite("http://xolotl:88/"))
using (SPWeb objWeb = objSitio.OpenWeb())
objWeb.AllowUnsafeUpdates = true;

string newFieldName = objWeb.Fields.Add("RegionFromCode", SPFieldType.Choice, true);
SPFieldChoice regionField = (SPFieldChoice)objWeb.Fields[newFieldName];
regionField.DefaultValue = "Europe";

string nombreCampoN = objWeb.Fields.Add("Antecedentes", SPFieldType.Text, true);
SPFieldText campoAntecedentes = (SPFieldText)objWeb.Fields[nombreCampoN];
campoAntecedentes.DefaultValue = "Ingrese los Antecedentes";

string nombreCampoNum = objWeb.Fields.Add("NoFolio", SPFieldType.Number, true);
SPFieldNumber campoFolio = (SPFieldNumber)objWeb.Fields[nombreCampoNum];

objWeb.AllowUnsafeUpdates = false;

SPFolder folder = objWeb.Folders[TextBox1.Text];
objWeb.AllowUnsafeUpdates = true;
SPFile file = folder.Files.Add(Filex.FileName, Filex.FileBytes, true);

// ERROR ERROR ERROR in the next Line,
file.Item["Antecedentes"] = DropDownList1.SelectedValue.ToString();
objWeb.AllowUnsafeUpdates = false;

Re: SharePoint - Development and Programming ArgumentException in columns value

Stefan Keir Gordon

Maybe it should be"Antecendentes", value);

Re: SharePoint - Development and Programming ArgumentException in columns value


Yes, it works pretty fine.

Really thanks for the help!