Microsoft Graph API - How to upload attachments to a list item - sharepoint

This question has been asked before with not much success.
The documentation is totally unclear too. It implies that to create a new list item one would do the following. But doesn't give a specific example on attachments.
The listitem documentation has a sneaky caveat right at the end which says that files/document libraries are treated as driveitems:
For document libraries, the driveItem relationship exposes the listItem as a driveItem
Right, so does that mean that all files are then related to driveitems? It seems closer as the driveitem docs talk about the following example (indicating site-related content which is SharePoint)
PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
But the above route doesn't specify a list-id either an item-id. So how does that fit in?
Which route do we hit to upload attachments on a list item? I have tried numerous requests:
PUT - https://graph.microsoft.com/v1.0/sites/root/lists/2696fba7-2cc5-482f-805e-a3dbf853e5e9/items/1/content
PUT - https://graph.microsoft.com/v1.0/sites/root/drive/items/1/createUploadSession (not list id though?)

To upload an small item (<4MB) into a Sharepoint Online document library or list which is not the default library, you can youse the following url syntax:
https://graph.microsoft.com/v1.0/sites/{SITE-ID}/drives/{DRIVE-ID}/root:/{FILENAME}:/content
{SITE-ID}: the id of sp site
{DRIVE-ID}: the id of drive (document library or list)
{FILENAME}: the name of the fie to upload
The "/root:" after the drive id is the important point.

Related

sharepoint list Vs library-developer point of view

What is the exact differnace between sharepoint list and library in developer point of view?
From a programmer's point of view, a Library is referenced through an SPDocumentLibrary object. SPDocumentLibrary inherits from the SPList class.
A Library is a List, but all lists are not libraries.
A Library is a specific implementation of a List intended for holding documents and metadata about the documents in the columns of the Library.
According this blog, http://www.networkworld.com/community/node/22731, use Library for storing documents, and use Lists for data, for example, a database record. Here's a direct quote
"I dug a little deeper and did find some points about list attachments
that suggest a list is probably not the best way to house documents if
the organization wants to take advantage of the full range of SP
features:
1) The title of the document is NOT indexed. So an end user would not
be able to search on the title of the document. Example: I attached a
document titled "Copy of Test Lobster.doc" but after incremental
indexing I get no results searching on the word "lobster." (medium
issue)
2) I can attach multiple documents to one list item, which could cause
problems (minor issue)
3) You can't (to the best of my knowledge) display the name of the
attached document. You only see the paperclip that signifies the
attachment. (major issue)
4) You don't have document control, no check-in or check-out. (major
issue)"
I would say except the content type their is no difference between list and library the base content type for both differs
for other programming differences kindly go through the following url
http://msdn.microsoft.com/en-us/library/dd490727(v=office.12).aspx
Libraries can hold files so a few additional methods/properties such as Item.File are valid for accessing the files. Anything involving the metadata columns will be much the same.
A document library is a specialized form of a list that has additional features to manage documents. This is also evident in the SDK where you can see that SPDocumentLibrary extends SPList.
Another way to think of the difference is that a document library contains documents while a list contains "contentless" documents (aka only metadata) - although this is slightly violated by means of attachments.
Difference:
List:
Don’t have Check in Check Out feature.
Have Major Versioning only.
We can attach multiple files to a List Item.
“Upload Document”, “Download a Copy” option not available.
Attached document is not searchable by Title.
Cannot display the name of attached file (only See paperclip symbol).
Library:
Have Check in Check Out feature.
Supports Minor (draft) and Major (Published) versioning.
1 Library item cannot have multiple files.
“Upload Document”, “Download a Copy” option is available.
Can perform search by title of a document.
Able to see Title of document and can also rename the title.
Internally SharePoint treats both library and list as a list.

Access List items in hidden "Forms" folder using Lists.GetListItems

Is it possible to access the list items in the (hidden) "Forms" subfolder of a document library using the Lists.GetListItems web service method? I need to set the content type of uploaded document templates using Lists.UpdateListItems, otherwise, document created from these templates will have the 'Document' content type and not the content type the template had been assigned to.
Lists.UpdateListItems works in subfolders of the "Forms"' folder, but I need the ows_UniqueId of the list item that represents the uploaded file, and I can only get it using List.GetListItems.
Is there maybe another method of uploading files to SharePoint document libraries, in which you can set the content type?
List.GetListItems expects you to pass it a view, if you don't it uses the defaults view. So what you need to do is create a seperate view which lists all items, and make this view list flat (not listing by subfolder).
Then query against this view.
Does this suck? Yes. Does SharePoint suck? I'll let you answer that question. I didn't write sharepoint, just telling you the way it is.
I don't understand the relationship between the content type of an uploaded document in a document library and the elements in the Forms subfolder.
What I'd try:
- Use Copy Web Service, method CopyIntoItems to upload the file, setting some properties, including the content type.
- Use Lists.GetListItems, with a CAM query specifying the file name and asking for ows_UniqueID property

Sharepoint Document Upload Page - Passing URL Variables?

Throughout my SharePoint site, I have several document repositories that are tied to primary keys from an external database. I have added custom columns in the document library metadata fields so that we will know which SharePoint documents correspond with which table entries. As a requirement, we need to have document uploads that have these fields automatically populated. For instance, I'd like to have the following url:
./Upload.aspx?ClassID=2&SystemID=63
So that when you upload any documents to this library, it automatically adds the ClassID and SystemID values to the corresponding ClassID and SystemID columns outlined in the SharePoint document library fields.
Is there any quick or easy way to do this, or will I have to completely rewrite the Upload.aspx script from scratch?
I think the only way to go is to create your own Upload.aspx page. Read more here.
Unfortunately, it looks like going custom is the only option for now. Here are some tips on how to code the submission page.
There is a corresponding entry that describes how to add a document to a document library here:
How do you upload a file to a document library in sharepoint?
Likewise, once you have a document library file handler, you can alter its metadata column values using this method:
http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?List=f0e16a1a-6fa9-4130-bcab-baeb97ccc4ff&ID=109
Essentially it's just
SPFile.Item["ColumnName"] = "Value";

Problem finding Item List Id in WSS 3.0

I'm having a hard time figuring out how to refer to a specific Item List within a list in SharePoint. I looked up the page in SharePoint Designer and found that the listitem is inside a custom made webpart inside a custom made webpage. I'm coding an event receiver and need to read the information that the user types into that listitem which is a textbox. Does anyone know the code to do this or how to get the guid for the specific list item?
I would appreciate any help I can get. I have tried looking all over the web for the answer. Thanks.
It might be a good idea to edit your question with exactly what you'd like to do with the information you read. However from what you've said so far:
The ID of the item being edited will already be passed through to the event receiver via SPItemEventProperties so there is no need to look it up. If you need to look up a different item in the list (or indeed in a different list altogether), the Accessing list items using the object model page on SharePoint Dev Wiki gives you all of the options. A good general rule is use SPQuery to get best performance on the whole.
Note: There is a pretty good page on the SharePoint Dev Wiki demonstrating how to write an event receiver. It shows how to query and obtain a list item title.
Update after comments:
Once you have an SPListItem object, you can find its GUID through the UniqueId property. In the "Accessing lists" wiki link I've provided above the code samples show how to use the Title property.
Every piece of data you need to access within SharePoint should be available through the object model. This is a simplification, but generally the pages themselves are rendered from template files on the server and combined with data in the database to display to the user. So editing the page programmatically or through its source isn't going to work.
Apologies if I'm making an incorrect assumption but you sound fairly new to SharePoint development. I strongly recommend you read at least the first few chapters of Inside Windows SharePoint Services 3.0 as the inner workings of SharePoint are important to get a good understanding of and this book should help a lot. There is a section of event receivers in it as well.
Have you looked at SharePoint.ListsService Webservice?
string url = "WSS Site URL";
SharePoint.ListsService.Lists lists = SharePoint.ListsService.Lists(url);
XmlNode list = lists.GetList("ListName");
XmlNode xlists = lists.GetListCollection();

Showing the list view web part for a list in another site

I cannot show the content of a document library using a list view contained in a web part located on my root web application.
Here is the site structure:
main_site
subsite1
Shared Documents
subsite2
Shared Documents
My webpart is located on the main_site.
In this webpart, I have a Sharepoint ListViewWebPart in which I want to show the Shared Documents from subsite1 for instance, but it does not seem to work. I get the following error:
List does not exist
The page you selected contains a list
that does not exist. It may have been
deleted by another user.
What is odd is that when I debug, I can see that the SPList is correctly initialized and contains the element of my list. However at the line Controls.Add(mylistview), is where the error occurs.
Here is the code I use to bind the list to my ListView:
SPList list = SPContext.Current.Site.AllWebs["subsite1"].Lists["Shared Documents"];
ListView lv = new ListView();
lv.ListId = list.ID.ToString();
lv.ViewId = list.DefaultView.ID.ToString();
lv.DataBind();
this.Controls.Add(lv);
Does someone have a logical explaination and solution to this problem?
The problem is that the list is in another site.
It is possible to use the ListViewWebPart to reference a list from another site in the same site collection. You need to use the WebId property to do this. Here is a code example.
Another option is to use SharePoint Designer to create a Data View Web Part. This will allow you to use a list from another site or the SharePoint web serivces to pull data in. The results look similar to the list view web part and there is some powerful functionality you can use. This is the first blog post I found that demonstrates this, there should be several others.
Finally, you could use the Content Query Web Part. You probably know this one already and it is really more for displaying and not manipulating data.
Edited to remove incorrect information.

Resources