Export (0) Print
Expand All

Imaging.Upload Method

Windows SharePoint Services 3
Uploads a file to a list on the current Web site.

Web Service: ImagingWeb Reference: http://<Site>/_vti_bin/Imaging.asmx

[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/ois/Upload", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/ois/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/ois/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode Upload (
	string strListName,
	string strFolder,
	byte[] bytes,
	string fileName,
	bool fOverWriteIfExist
)

Parameters

strListName

The name of the list on the current Web site.

strFolder

The relative path from the root of the list to the target folder.

bytes

The binary content in the file to upload.

fileName

The file name to use as item name in the list.

fOverWriteIfExist

A Boolean value that indicates whether to overwrite a file with the same name. A FileExists exception is thrown if the item exists and fOverWriteIfExist is not true.

Return Value

A Microsoft.SharePoint.SoapServer.SoapXml object that returns the last modified date of the item if the operation succeeds.
<results xmlns="http://schemas.microsoft.com/sharepoint/soap/ois/" 
  lastmodified="..."/>

Exception typeCondition

0x1

ListNotFound: The requested list is not found.

0x2

IsNotLibrary: The requested list, although found, is not a picture library.

0x3

ItemNotFound: The requested list item is not found.

0x4

FolderNotFound: The requested folder is not found.

0x5

InvalidArgument: One or more arguments are not valid.

0x6

FileExists: The file already exists, and the user does not specify the overwrite option.

The following code example uploads an image named "Red Figure2.gif" to the "1" folder in the "My Pictures" library on http://MyServer/sites/mynewsite. The code assumes that the site and the picture library already exist, that you have permissions on the server, and that the picture library contains some items. If the site and picture library do not exist, see the second example.

Web_Reference.Imaging imgws = new Web_Reference.Imaging();
imgws.Credentials = System.Net.CredentialCache.DefaultCredentials;
imgws.Url = "http://MyServer/sites/mynewsite/_vti_bin/imaging.asmx";
System.Xml.XmlDocument resdoc= new System.Xml.XmlDocument();
System.Xml.XmlNode resnode = 
   resdoc.CreateNode(System.Xml.XmlNodeType.Element,"Result","");
Byte[] b =System.Text.Encoding.Unicode.GetBytes
   ("R0lGODlhCQALAJEAAAoLBv///wAAAP///
   yH5BAEAAAMALAAAAAAJAAsAAAIdlIdmETDAxBAxosm
   CvE9fNU0K40Ae1ZBftq0t9xYAOw==");
imgws.Upload("My Pictures","1",b,"Red Figure2.gif", true);

The following code example shows how to create the site and the picture library required in the earlier example.

NoteNote:

You must be a member of the Administrators site group on the server that is running Microsoft Windows SharePoint Services to be able to add a reference to the Admin Web service and perform the required actions.

Web_Reference.Admin adminws = new Web_Reference.Admin();
adminws.Credentials= System.Net.CredentialCache.DefaultCredentials;
try
{
   adminws.CreateSite("http://MyServer/sites/my2003site",
      "My 2003 New Site","Manage content and pictures for year 
         2003",1033,"MPS#0",
      "DOMAIN\\User_Alias","Display_Name",
      "someone@example.com","","");
}
catch(Exception ex)
{
   MessageBox.Show(ex.Message);
}
Web_Reference.Lists listsws = new Web_Reference.Lists();
listsws.Credentials = System.Net.CredentialCache.DefaultCredentials;
listsws.Url = "http://MyServer/sites/mynewsite/_vti_bin/lists.asmx";
try
{
   listsws.AddList("My Pictures","My personal pictures",109);
}
catch(Exception ex1)
{
   MessageBox.Show(ex1.Message);
}
Web_Reference.Imaging imgws = new Web_Reference.Imaging();
imgws.Credentials = System.Net.CredentialCache.DefaultCredentials;
imgws.Url = "http://MyServer/sites/mynewsite/_vti_bin/imaging.asmx";
System.Xml.XmlDocument resdoc= new System.Xml.XmlDocument();
System.Xml.XmlNode resnode = 
   resdoc.CreateNode(System.Xml.XmlNodeType.Element,"Result","");
Byte[] b =System.Text.Encoding.Unicode.GetBytes
   ("R0lGODlhCQALAJEAAAoLBv///wAAAP///
   yH5BAEAAAMALAAAAAAJAAsAAAIdlIdmETDAxBAxosm
   CvE9fNU0K40Ae1ZBftq0t9xYAOw==");
imgws.Upload("My Pictures","1",b,"Red Figure2.gif", true);

Community Additions

ADD
Show:
© 2014 Microsoft