Creating directories

Last post 09-13-2005, 12:11 AM by Adam. 10 replies.
Sort Posts: Previous Next
  •  09-07-2005, 1:10 PM 10204

    Creating directories

    Could you tell me how to create directories programaticly, in c# , that users coul upload images into them?
    i've managed to create the dirs but when i try to upload images to there the image aplication says: unable to upload.
    i've tryed the following code:
    Programmatically set the image gallery path 

     Example:    var  folder = "whatever";
       string phyfolder=Server.MapPath(folder);
       System.IO.Directory.CreateDirectory(phyfolder);
       Editor1.Setting["security:ImageGalleryPath"]=
       Editor1.Setting["security:MediaGalleryPath"]=
       Editor1.Setting["security:FlashGalleryPath"]=
       Editor1.Setting["security:FilesGallaryPath"]=
        folder
    but it seem's not to work even with some alterations
  •  09-07-2005, 1:31 PM 10205 in reply to 10204

    Re: Creating directories


    Please try the following code:

            void SetUploadsFolder(string folder)
            {
                string phyfolder=Server.MapPath(folder);
                System.IO.Directory.CreateDirectory(phyfolder);
                
                //see security.config
                Editor1.Setting["security:ImageGalleryPath"]=
                Editor1.Setting["security:MediaGalleryPath"]=
                Editor1.Setting["security:FlashGalleryPath"]=
                Editor1.Setting["security:FilesGallaryPath"]=
                    folder;
            }

           
        SetUploadsFolder("~/Uploads/Users/Tim/");


    If you have problems with it, please post your error message.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-09-2005, 2:00 PM 10304 in reply to 10205

    Re: Creating directories

    What file do I place this code in to get it to work?  And is it possible to have the folder be ~/Username/Uploads?
  •  09-09-2005, 2:03 PM 10305 in reply to 10304

    Re: Creating directories

    Just put the above code into your page_load event.
     
    >>And is it possible to have the folder be ~/Username/Uploads?
    Yes, you can.

    Please check the following example:

    Personalization and Programmatic Security Example
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-09-2005, 2:20 PM 10307 in reply to 10305

    Re: Creating directories

    The code must need to be changed some to put into my page_load event?  I'm using VB as well, I'm not sure if that makes a difference.  So the code SetUploadsFolder("~/Uploads/Users/Tim/");  needs to go in the page_load event as well?
  •  09-09-2005, 3:15 PM 10320 in reply to 10307

    Re: Creating directories

    This is an example:
     
    <%@ Page Language="vb"%> <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %> <html> <head> <title>Personalization and Programmatic Security Example</title> </head> <body> <form runat="server"> <asp:radiobuttonlist style="BORDER:#c0c0c0 1px solid;" BgColor="#f5f5f5" id="RadioList" runat="server" autopostback="True" RepeatLayout="Table" RepeatColumns="3" CellPadding="0" CellSpacing="0" RepeatDirection="Horizontal" onselectedindexchanged="security_Changed"> <asp:ListItem value="Administrators"> <span style="width:100">Administrators</span></asp:ListItem> <asp:ListItem value="Members"> <span style="width:100">Members</span></asp:ListItem> <asp:ListItem value="Guest"> <span style="width:100">Guest</span></asp:ListItem> <asp:ListItem value="John"> <span style="width:100">John (admin)</span></asp:ListItem> <asp:ListItem value="Mary"> <span style="width:100">Mary (sales)</span></asp:ListItem> <asp:ListItem value="Tim"> <span style="width:100">Tim (financial)</span></asp:ListItem> </asp:radiobuttonlist> <br /> <CE:Editor id="Editor1" EditorWysiwygModeCss="../example.css" runat="server" AutoConfigure="Simple"></CE:Editor> </form> </body> </html> <script runat="server"> Public Sub Page_Load(sender As object, e As System.EventArgs) If Not Page.IsPostBack Then Editor1.SecurityPolicyFile = "default.config" SetUploadsFolder("~/Uploads/Member/") Editor1.ReadOnly = false End If End Sub public Sub security_Changed(sender As object, e As System.EventArgs) Dim temp As String = "" Select Case RadioList.SelectedItem.Value case "Administrators": Editor1.SecurityPolicyFile = "Admin.config" SetUploadsFolder("~/Uploads/") case "Members": Editor1.SecurityPolicyFile = "default.config" SetUploadsFolder("~/Uploads/Member/") case "Guest": Editor1.SecurityPolicyFile = "Guest.config" SetUploadsFolder("~/Uploads/Guest/") 'case "Banned": ' Editor1.ReadOnly = true case "John": Editor1.SecurityPolicyFile = "Admin.config" SetUploadsFolder("~/Uploads/Users/John/") case "Mary": Editor1.SecurityPolicyFile = "default.config" SetUploadsFolder("~/Uploads/Users/Mary/") case "Tim": Editor1.SecurityPolicyFile = "default.config" SetUploadsFolder("~/Uploads/Users/Tim/") End Select End Sub Sub SetUploadsFolder(ByVal folder As String) Dim phyfolder As String = Server.MapPath(folder) 'see security.config Editor1.Setting("security:ImageGalleryPath")=folder Editor1.Setting("security:MediaGalleryPath")=folder Editor1.Setting("security:FlashGalleryPath")=folder Editor1.Setting("security:FilesGallaryPath")=folder End Sub </script>

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-09-2005, 5:02 PM 10323 in reply to 10320

    Re: Creating directories

    I got that to work, thanks!  Now the problem is that when I click to add a link or image I see all the folders in the Upload folder.  I only want to see the one Member folder.  How would I fix this?
     I don't know what happened, but now it's all of a sudden working.
  •  09-10-2005, 4:59 PM 10341 in reply to 10320

    Re: Creating directories

    It's still not going to the correct user folder, it's still showing all the folders in the Uplodads folder....below is my code...any ideas:
     
    <script runat="server">
     Public Sub Page_Load(sender As object, e As System.EventArgs)
     
      If Page.IsPostBack Then
       Editor1.SecurityPolicyFile  = "default.config"
                SetUploadsFolder("~/Uploads/Wendi/")
                Editor1.ReadOnly = false
       Literal1.Text = "<h3>The HTML you typed is...</h3><br>"
       Literal1.Text += Server.HtmlEncode(Editor1.Text)
      Else
       Editor1.Text = "Type Here"
      End If
      
     End Sub 
     
    Sub SetUploadsFolder(ByVal folder As String)
            Dim phyfolder As String = Server.MapPath(folder)
            'see security.config
            Editor1.Setting("security:ImageGalleryPath")=folder
            Editor1.Setting("security:MediaGalleryPath")=folder
            Editor1.Setting("security:FlashGalleryPath")=folder
            Editor1.Setting("security:FilesGalleryPath")=folder
        End Sub
     
     public Sub Submit(sender As object, e As System.EventArgs)
      Literal1.Text = "<h2>The HTML you typed is...</h2><br>"
      Literal1.Text += Server.HtmlEncode(Editor1.Text)
     End Sub
    </script>
  •  09-12-2005, 9:50 PM 10457 in reply to 10341

    Re: Creating directories

    use the following code:
     
    <script runat="server">
     Public Sub Page_Load(sender As object, e As System.EventArgs)
     
      If Page.IsPostBack Then
       Editor1.SecurityPolicyFile  = "default.config"
                SetUploadsFolder("~/Uploads/Wendi/")
                Editor1.ReadOnly = false
       Literal1.Text = "<h3>The HTML you typed is...</h3><br>"
       Literal1.Text += Server.HtmlEncode(Editor1.Text)

      Else
       Editor1.Text = "Type Here"
      End If

      
     End Sub 
     
    Sub SetUploadsFolder(ByVal folder As String)
            Dim phyfolder As String = Server.MapPath(folder)
            'see security.config
            Editor1.Setting("security:ImageGalleryPath")=folder
            Editor1.Setting("security:MediaGalleryPath")=folder
            Editor1.Setting("security:FlashGalleryPath")=folder
            Editor1.Setting("security:FilesGalleryPath")=folder
        End Sub
     
     public Sub Submit(sender As object, e As System.EventArgs)
      Literal1.Text = "<h2>The HTML you typed is...</h2><br>"
      Literal1.Text += Server.HtmlEncode(Editor1.Text)
     End Sub

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-13-2005, 12:06 AM 10460 in reply to 10457

    Re: Creating directories

    Thanks!  Working good.
  •  09-13-2005, 12:11 AM 10461 in reply to 10460

    Re: Creating directories

View as RSS news feed in XML