Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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);
share|improve this answer
    
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 '13 at 19:51
    
Microsoft.SharePoint.ApplicationPages.RteUploadDialogPage which is in Microsoft.SharePoint.ApplicationPages.dll –  Steve Lineberry Feb 20 '13 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? –  Steve Lineberry Feb 20 '13 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 '13 at 20:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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