0

Trying to create folder in filesystem. But it doesn't work for general domain users, only for admins.

I've tried

_strArticlePath = SPUtility.GetGenericSetupPath(Path.Combine(_strArticleStoragePath, strArticleId)); 



            SPUserToken sysToken = null;
            using (var spSite = new SPSite(SPContext.Current.Site.ID))
            {

                sysToken = GetSystemToken(spSite);

                using (var impersonatedSite = new SPSite(SPContext.Current.Site.ID, sysToken))
                {                      
                    using (var web = impersonatedSite.OpenWeb())
                    {                         
                        try
                        {
                            Directory.CreateDirectory(_strArticlePath);   
                        }
                        catch (Exception ex)
                        {
                            WriteLog("Create Directory", ex.Message);
                        }
                    }
                }
            }

and this one

        SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (var site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (var impersonateWeb = site.OpenWeb(SPContext.Current.Web.ID))
                    {
                        impersonateWeb.AllowUnsafeUpdates = true;
                        Directory.CreateDirectory(_strArticlePath);
                    }
                }
            });

And both doesn't work. Advise pls.

1 Answer 1

0

First, keep in mind that letting non-admins create files/folders on the HDD is a risky security threat. I'm sure you can imagine. Second, SP is sort-of designed to be a better way to store files. So, in general, you are trying to do something that MS hoped you would not try to do.

The problem is most likely that you don't have the NTFS permissions set up on the HDD folder that you are working-in. Try setting the NTFS permissions (via file Explorer) to "Modify" for "domain users" or "Everyone" for the path (that you refer to as "_strArticleStoragePath").

2
  • I understand this. So You mean if I want my web part to work everywhere I have to store files in sp not in filesystem? PS. I can't give folder permissions manually.
    – Ars
    Commented Jul 13, 2013 at 2:46
  • Also, you can refer to a SP folder as a web address or as a network share. Maybe that might make things easier, as an alternative. eg. http : //myserver/subfolder/ = \\myserver\subfolder\
    – tgolisch
    Commented Jul 13, 2013 at 21:59

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.