Example #1
0
        public Hashtable CreateFolderInLibrary(SPUserCodeWorkflowContext context, string folderName, string libraryName, string folderPath)
        {
            char[] filenameChars = folderName.ToCharArray();
            foreach (char c in filenameChars)
            {
                if (!SPEncode.IsLegalCharInUrl(c))
                {
                    folderName = folderName.Replace(c.ToString(), "");
                }
            }
            results["result"] = string.Empty;
            try
            {
                using (SPSite site = new SPSite(context.CurrentWebUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList library = web.Lists[libraryName];

                        if (library != null)
                        {
                            string folderUrl = CreateFolder(library, folderName, folderPath, web);
                            results["result"]   += "Created Finished";
                            results["folderUrl"] = folderUrl;
                        }
                        else
                        {
                            results["result"]    = string.Format("Library ({0}) not found.", libraryName);
                            results["folderUrl"] = string.Empty;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                results              = new Hashtable();
                results["result"]    = e.ToString();
                results["folderUrl"] = string.Empty;
            }

            return(results);
        }