3

I have a wiki library with pages and a document library which I've configured to be an assets library. How do I prevent sharepoint from creating a directory structure for file uploads?

The wiki pages are organized like so:

Root/Finance Dept/Payroll/Best_Practices.aspx

When a user uploads a file from the Best_Practices.aspx wiki page, it creates an obnoxious directory structure under the target document library:

/Root/Finance Dept/Payroll/Best_Practices/Sample_File.PDF

The issue being that Best_Practices.PDF might also apply to another area under payroll, and so it doesn't make sense for it to sit under the Best_Practices folder. Also, when files get hidden deep down in the folder structure, they tend to get missed and we end up with duplicate files because most users wont run a search.

Is there a way to prevent this without implementing content approval, or other draconian methods of enforcement?

1 Answer 1

1

If it isn't an asset library or the Source querystring isn't passed in, it looks like it won't create the structure. See the reflectored code below:

                string text2 = "";
                string text3 = "";
                if (sPList.IsSiteAssetsLibrary)
                {
                    text2 = base.Request.QueryString.Get("Source");
                    if (string.IsNullOrEmpty(text2))
                    {
                        this.ErrorLabel.Text = SPHttpUtility.HtmlEncode(SPResource.GetString("CouldNotUploadFile", new object[]
                        {
                            postedFile.FileName
                        }));
                        return;
                    }
                    try
                    {
                        Uri uri = new Uri(text2);
                        text2 = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
                        text2 = "/" + text2;
                    }
                    catch (UriFormatException ex)
                    {
                        this.ErrorLabel.Text = SPHttpUtility.HtmlEncode(ex.Message);
                        return;
                    }
                    string extension = Path.GetExtension(text2);
                    if (!string.IsNullOrEmpty(extension))
                    {
                        text2 = text2.Substring(0, text2.LastIndexOf(extension, StringComparison.Ordinal));
                    }
                    text2 = base.Web.GetWebRelativeUrlFromUrl(text2);
                    text2 = sPList.RootFolderUrl + ((!string.IsNullOrEmpty(text2)) ? ("/" + text2) : string.Empty);
                    text3 = text2 + '/' + text;
                }
                else
                {
                    text3 = sPList.RootFolder.ServerRelativeUrl + '/' + text;
                }

...

                SPFile sPFile = null;
                SPFolder sPFolder = null;
                text2 = base.Web.GetWebRelativeUrlFromUrl(text2);
                try
                {
                    if (sPList.IsSiteAssetsLibrary && !string.IsNullOrEmpty(text2))
                    {
                        if (text2.StartsWith("/"))
                        {
                            text2 = text2.Substring(1);
                        }
                        string[] array = text2.Split(new char[]
                        {
                            '/'
                        });
                        SPFolder sPFolder2 = null;
                        string text4 = null;
                        string[] array2 = array;
                        for (int i = 0; i < array2.Length; i++)
                        {
                            string text5 = array2[i];
                            if (string.IsNullOrEmpty(text4))
                            {
                                text4 = text5;
                            }
                            else
                            {
                                text4 = text4 + "/" + text5;
                            }
                            sPFolder2 = new SPFolder(base.Web, text4);
                            if (!sPFolder2.Exists)
                            {
                                sPFolder2.ParentFolder.SubFolders.Add(sPFolder2.Url);
                            }
                        }
                        sPFolder = sPFolder2;
                    }
                    else
                    {
                        sPFolder = sPList.RootFolder;
                    }
                    sPFile = sPFolder.Files.Add(text3, postedFile.InputStream, this.OverwriteFile.Checked, string.Empty, false);
4
  • What .dll did you reflect to find this? As well, what would your recommended approach to getting around this be? Changing the asset library property might be an option, but it is probably referenced in other places which would be an issue.
    – Ray
    Feb 20, 2013 at 19:51
  • Microsoft.SharePoint.ApplicationPages.RteUploadDialogPage which is in Microsoft.SharePoint.ApplicationPages.dll Feb 20, 2013 at 19:59
  • Why don't you tell the users to select a different library in the upload box. Maybe one that isn't an asset library? Feb 20, 2013 at 20:00
  • I was hoping to make some modifications once we found where in the code this was happening and sort of go half-way; We have enough files to exceed the recommended 1000 items per folder limit, but not so many that we need 4-5 levels of sub directories.
    – Ray
    Feb 20, 2013 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.