Seeing uploaded documents in Sharepoint

Silas2
Silas2 used Ask the Experts™
on
I'm using code to upload documents to a folder created thru code. Is there a way to see these items thru the SP front end. I can't see the SPFolder which I created thru code,with the front end but I can make folders with the SP front end which I can see. Apart from writing my own file listing code, is there a way to 'explore' the SP virtual file system?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Did you call the .Update() methods in your code?
Greg BessoIT Solutions Engineer

Commented:
You could always manually put a link to it on navigation, or access via Explorer view.
 

Author

Commented:
The file are definately getting up there because I can request the individually, but I can't see the folder. Do you know why a folder created with with SP front end can be seen, but an SPFolder created thru code isn't listed?
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Greg BessoIT Solutions Engineer

Commented:
I think because a folder you create manually isn't considered to be a document library or list, so it's not part of the "view all site content" content.
One snipped I saw online was....
SPSite site = SPContext.Current.Site as SPSite;
SPWeb web = site.RootWeb as SPWeb;
try
{ //Create a new library as the permanent library
Guid customListID = web.Lists.Add("CUSTOM DOCUMENT LIBRARY", "CUSTOM DOCUMENT LIBRARY", SPListTemplateType.DocumentLibrary);
web.Update();
}
 
MSDN link also...
http://msdn.microsoft.com/en-us/library/ms425818.aspx
 

Commented:
A folder is treated like the title of an item. So when you create a folder you must call the update method, so again did you???

Can you post your code?

Author

Commented:

public string SaveFileToDestination(string sProductOrDev, string destinUrl, byte[] contents)
        {

            try
            {
                if (sProductOrDev == "Dev")
                {
                    string sPath = HostingEnvironment.ApplicationPhysicalPath + destinUrl;
                    File.WriteAllBytes(sPath, contents);

                }
                else
                {

                    SPWeb parentSite = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(HttpContext.Current );
                    EnsureParentFolder(destinUrl, parentSite,contents );
                    parentSite.Files.Add(destinUrl, contents);
                }
                return "";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        private void EnsureParentFolder(string destinUrl, SPWeb parentSite, byte[] contents)
        {
            destinUrl = parentSite.GetFile(destinUrl).Url;
            int index = destinUrl.LastIndexOf("/");
            string parentFolderUrl = string.Empty;
            if (index > -1)
            {
                parentFolderUrl = destinUrl.Substring(0, index);

                SPFolder parentFolder = parentSite.GetFolder(parentFolderUrl);

                if (!parentFolder.Exists)
                {
                    SPFolder currentFolder = parentSite.RootFolder;
                    foreach (string folder in parentFolderUrl.Split('/'))
                    {
                        currentFolder = currentFolder.SubFolders.Add(folder);
                    }
                }
            }
        }

Open in new window

Commented:
try this:

SPFolderCollection folders = parentSite.GetFolder(site.Lists["YOUR DOC LIB"].RootFolder.ServerRelativeUrl.ToString()).SubFolders;
folders.Add("Newfolder");

Author

Commented:
Thanks for that help, I'm sorry I've been dilatory about trying this but I got sidelined, I'll check out your suggestion asap.

Author

Commented:
To return the SPFolder once created do you call:
SPFolder fldRet = parentSite.GetFolder(site.Lists["YOUR DOC LIB"].RootFolder.ServerRelativeUrl.ToString()).SubFolders["FolderName"]?

Author

Commented:
Actually, sorry to spin the question in the opposite direction, but after thinking about it, I think it is quite a good thing that the folder for the code-uploaded files cannot be seen easily through the front end as the filenames have no human-readable meaning, so the question would become how to prevent the folder and its contents from ever becoming visible (or at least listable) thru the front, but would remain available to the web part code?
Commented:
Let's take a step back.

1.- I asked if you called the update methods.
2.- Then you sent me your code and it looked like you wanted to create the folder on the WebDAV file system.
3.- I sent you code that would write the folder to the "pseudo" file system.
4.- Now your asking me how to hide folder.
=========================================================
We're basically there, but in the wrong order. The below creates 2 folders, 1 visible in a list view web part... YOU MUST enable folders in the List Settings, or it will just be another Title.

The 2nd creates a folder, but it's not visible in a listview.



SPSite oSite = new SPSite("SITE URL";
SPWeb oWeb = oSite.OpenWeb();

//This creates a folder visible in the LISTVIEW
SPList oList = oWeb.Lists["YOUR LIST"];
SPListItem oItem = oList.Folders.Add(oList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
oItem["Title"] = DateTime.Now.ToFileTimeUtc().ToString();
oItem.Update();
oList.Update();

//This creates a folder NOT VISIBLE IN THE LISTVIEW WEBPART
SPFolderCollection folders = oWeb.GetFolder(oList.RootFolder.ServerRelativeUrl.ToString()).SubFolders;
folders.Add(DateTime.Now.ToFileTimeUtc().ToString());

oWeb.Dispose();
oSite.Dispose();

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial