C# 4.0 错误:是字段,但用作类型
这是完整的代码。C# 4.0 错误:是字段,但用作类型,c#-4.0,C# 4.0,这是完整的代码。 我不知道它为什么显示错误。我搜索了错误“是一个字段,但用作类型”,我尝试了,但没有帮助。由于我是新手,请提供解决方案代码。提前谢谢。这几行代码的目的是什么 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using S
我不知道它为什么显示错误。我搜索了错误“是一个字段,但用作类型”,我尝试了,但没有帮助。由于我是新手,请提供解决方案代码。提前谢谢。这几行代码的目的是什么
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication5
{
public class ClientContext
{
private string p;
public ClientContext(string p)
{
// TODO: Complete member initialization
this.p = p;
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//First construct client context, the object which will be responsible for
//communication with SharePoint:
private ClientContext context = new ClientContext("@url");
//then get a hold of the list item you want to download, for example
public List list;
public ClientContext
{
list = context.Web.Lists.GetByTitle("001_CFR_DPV_COST_REV_SHARING");
}
//note that data has not been loaded yet. In order to load the data
//you need to tell SharePoint client what you want to download:
context.Load(result, items=>items.Include(
item => item["Title"],
item => item["FileRef"]
));
//now you get the data
context.ExecuteQuery();
//here you have list items, but not their content (files). To download file
//you'll have to do something like this:
var item = items.First();
//get the URL of the file you want:
var fileRef = item["FileRef"];
//get the file contents:
FileInformation fileInfo = File.OpenBinaryDirect(context, fileRef.ToString());
using (var memory = new MemoryStream())
{
byte[] buffer = new byte[1024 * 64];
int nread = 0;
while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0)
{
memory.Write(buffer, 0, nread);
}
memory.Seek(0, SeekOrigin.Begin);
// ... here you have the contents of your file in memory,
// do whatever you want
}
}
}
什么是类Form1中的publicclientcontext{}
似乎您打算为另一个类中的类创建构造函数,而对于编译器来说,它更像是一个属性,但没有访问器(get、set),就好像它是这样的类型或smth
试着把它放进去;设置如果要创建属性,请在内部访问器:
public partial class Form1 : Form
{
...
public ClientContext
{
list = context.Web.Lists.GetByTitle("001_CFR_DPV_COST_REV_SHARING");
}
}
或者将其改为“方法”:
public List Context
{
get
{
list = context.Web.Lists.GetByTitle("001_CFR_DPV_COST_REV_SHARING");
return list;
}
}
我很抱歉不得不这样说;但是,要么是粘贴的代码出错,要么是其中存在多个严重错误。我不得不假设这是最后的选择。在这种情况下,最好从一个基本的C#教程开始,自己找出错误的原因。有很多语法错误,你的代码根本无法生成。你想在这里实现什么?调用包含这些列的列表?那么!我想你应该更新你的问题,因为标题与描述不符。
public void GetClientContext()
{
list = context.Web.Lists.GetByTitle("001_CFR_DPV_COST_REV_SHARING");
}