<asp:FileUpload ID=”File1″ runat=”server” />
<asp:Button ID=”Button1″ runat=”server”
Text=”Button” onclick=”Button1_Click” />
protected void Button1_Click(object sender, EventArgs e)
{
CopyServiceToSharePoint.Copy copyService = new CopyServiceToSharePoint.Copy();
copyService.Url = "http://SERVER/sites/YOURSITE/_vti_bin/copy.asmx";
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;
if (File1.PostedFile == null)
return;
Stream fStream = File1.PostedFile.InputStream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
string sourceUrl = File1.PostedFile.FileName.ToString();
string filename = System.IO.Path.GetFileName(sourceUrl);
string[] destinationURL = { “http://SERVER/sites/YOURSITE/Shared%20Documents/” + filename };
CopyServiceToSharePoint.CopyResult cResult1 = new CopyServiceToSharePoint.CopyResult();
CopyServiceToSharePoint.CopyResult cResult2 = new CopyServiceToSharePoint.CopyResult();
CopyServiceToSharePoint.CopyResult[] cResultArray = { cResult1, cResult2 };
CopyServiceToSharePoint.FieldInformation fFiledInfo = new CopyServiceToSharePoint.FieldInformation();
fFiledInfo.DisplayName = “Description”;
fFiledInfo.Type = CopyServiceToSharePoint.FieldType.Text;
fFiledInfo.Value = “Sample Description”;
CopyServiceToSharePoint.FieldInformation[] fFiledInfoArray = { fFiledInfo };
uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationURL, fFiledInfoArray, contents, out cResultArray);
}
I need to find a column id /guid to create a content type.
Solution:
- Navigate to sharepoint 12 hive /Template/Layouts/
- Create a folder “SiteColumnList”
- Create a SiteColumn.aspx file
- Copy and past the code into SiteColumn.aspx
- Go to http://Server/_layouts/SiteColumnList/SiteColumn.aspx
<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>
<%@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master” Inherits=”Microsoft.SharePoint.WebControls.LayoutsPageBase” %>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Import Namespace=”Microsoft.SharePoint.Administration” %>
<%@ Import Namespace=”Microsoft.SharePoint.Utilities” %>
<%@ Import Namespace=”System.Reflection” %>
<%@ Import Namespace=”System.Data” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<script runat=”server”>
protected override void OnLoad(EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;
SPRoleDefinitionCollection siteRoleCollection = web.RoleDefinitions;
SPRoleDefinition roleDefinition = siteRoleCollection["Full Control"];
//Is user in the role
if ((usersRoles.Contains(roleDefinition)) || web.CurrentUser.IsSiteAdmin)
{
if (IsPostBack != true)
{
initPage();
}
}
else
{
Response.Redirect(“/_layouts/accessdenied.aspx”);
}
}
public void initPage()
{
DataTable TColumns = new DataTable();
TColumns.Columns.Add(“ColumnName”);
TColumns.Columns.Add(“ColumnID”);
TColumns.Columns.Add(“ColumnDescription”);
SPBoundField fldNameField = new SPBoundField();
fldNameField.DataField = “ColumnName”;
fldNameField.HeaderText = “Column Name”;
fldNameField.ItemStyle.Wrap = false;
SPBoundField fldIDField = new SPBoundField();
fldIDField.DataField = “ColumnID”;
fldIDField.HeaderText = “Column ID”;
fldIDField.ItemStyle.Wrap = false;
SPBoundField fldDescriptionField = new SPBoundField();
fldDescriptionField.DataField = “ColumnDescription”;
fldDescriptionField.HeaderText = “Column Description”;
grdSiteColumns.Columns.Add(fldNameField);
grdSiteColumns.Columns.Add(fldIDField);
grdSiteColumns.Columns.Add(fldDescriptionField);
foreach (SPField field in SPContext.Current.Web.Fields)
{
string[] rowValue = new string[3];
rowValue[0] = field.Title;
rowValue[1] = field.Id.ToString();
rowValue[2] = field.Description;
TColumns.Rows.Add(rowValue);
}
TColumns.AcceptChanges();
grdSiteColumns.DataSource = TColumns;
grdSiteColumns.DataBind();
}
</script>
<asp:content id=”PageTitle” runat=”server” contentplaceholderid=”PlaceHolderPageTitle”>
Site Column IDs
</asp:content>
<asp:content id=”PageTitleInTitleArea” runat=”server” contentplaceholderid=”PlaceHolderPageTitleInTitleArea”>
Site Column IDs
</asp:content>
<asp:content id=”Main” runat=”server” contentplaceholderid=”PlaceHolderMain”>
<p> <sharepoint:spgridview id=”grdSiteColumns” runat=”server” autogeneratecolumns=”false” /> </p>
</asp:content>
SharePoint syntax of Norwegian is not the same as the English edition. In the english version you use commas (,) syntax. The Norwegian version used a semicolon (;).