No me hago responsable si copiaste mal algún código que sale en las páginas de este sitio.
Ojalá sea de ayuda para más de alguno este sitio.
Se agradece si deja algún comentario.

jueves, 2 de diciembre de 2010

Validar si existe carpeta o biblioteca de documento

Ref: http://mundeep.wordpress.com/2009/02/24/checking-if-a-spfolder-exists/

Checking if a SPFolder Exists

Posted by mundeep on February 24, 2009
Ran into a colleague’s code that was incorrectly trying to check if a folder existed. It was something like:
1private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
2    SPFolder folder = parentWeb.GetFolder(folderName);
3    if (folder == null) {
4        return false;
5    }
6    else {
7         return true;
8    }
9}
however this always returns an actual SPFolder object, and the correct way is to check the Exists property of the returned object ie:
1private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
2    SPFolder folder = parentWeb.GetFolder(folderName);
3    return folder.Exists;
4}
NB: Yes, this post is almost identical to my earlier one about checking if an SPWeb object exists.

No hay comentarios:

Publicar un comentario