次の方法で共有


Listless

This is something really silly. Any list that is a part of a site can be accessed by using a small snippet that looks more or less like this:

SPSite site = new SPSite(https://localhost");
SPWeb web = site.OpenWeb();
SPList list = web.Lists[index];

Now lets say you want to add an item to an ordinary list. The snippet would go like:

web.Lists[index].Items.Add(..some parameters...);
..add the values for the individual fields...
web.Lists[index].Update();

If, however the list in question turns out to be a document library then you will be pleasantly surprised to see that the file you just added is nowhere to be seen. The catch lies in that a document library also supports folders. So the modification becomes:

web.Lists[index].RootFolder.Files.Add(..some parameters..);

The parameters in this case are the byte array containing the content of the file and the destination URL in terms of the root folder of the document library.

Funny!

/Harsh