Sharepoint以编程方式添加列表项附件(使用javascript)

时间:2014-06-02 11:56:46

标签: javascript sharepoint ecmascript-5

我需要使用javascript(客户端对象模型)向列表项添加附件。我知道如何使用C#如following.

来做到这一点
string srcUrl = textBox1.Text;

if (! File.Exists(srcUrl))
{
    throw new ArgumentException(String.Format("{0} does not exist", 
        srcUrl), "srcUrl");
}

FileStream fStream = File.OpenRead(srcUrl);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();

Web_Reference_Folder.Lists listService = 
    new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

try
{
    string addAttach = listService.AddAttachment("List_Name", "3", 
        fileName, contents);
    MessageBox.Show(addAttach);
}

catch (System.Web.Services.Protocols.SoapException ex)
{
    MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + 
        ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace);
}

如何使用客户端的javascript来完成。

0 个答案:

没有答案