Solved

Security: The requested template has been denied access to D:\wwwroot.

Posted on 2011-09-21
8
316 Views
Last Modified: 2013-12-24
I am trying to create folders on a hosted website on the same level as the root. Testing internally I got this loop to work but I had all permissions.

On the hosted site I know I don't have permision for the level D:\wwwroot. I have permissions from our domain onwards which looks like this: D:\wwwroot\imailroom.ca.

How can I change the code below to start at our domain?
<cfset strCommonPath = "/" & "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>
<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strFullHostPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(DirectoryTree,Directory,"\")>

    <cfif DirectoryExists(DirectoryTree)> 
  <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
Comment
Question by:Shawn
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 36577964

The root folder can be referred to using:     expandPath('/')

I am not sure which variable you want to set to that, but that will get you the full path to your root.
0
 
LVL 1

Author Comment

by:Shawn
ID: 36581888
yep, using expandpath. just a little confused. Code is improving...Now I manage to create folders in the root but not quite the way I want.

In the example below I am creating both the folders TestClient and iEnvelopes but they are both being created at the root whereas iEnvelopes is actually a subfolder of TestClient.

any idea what I'm doing wrong here?
<cfset strCommonPath = "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(strFilePath,Directory,"\")>
 
     <cfif DirectoryExists(DirectoryTree)> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
 
LVL 1

Author Comment

by:Shawn
ID: 36581903
oops, missign a line. see code below
<cfset strCommonPath = "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(strFilePath,Directory,"\")>
 
     <cfif DirectoryExists(DirectoryTree)>
     <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
 
LVL 1

Author Comment

by:Shawn
ID: 36582355
got it to work with code below.
<cfset strCommonPath = "\" & "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = strFilePath>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
	 <cfset DirectoryTree = ListAppend(DirectoryTree,Directory,"\")>

     <cfif DirectoryExists(DirectoryTree)> 
     <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#">
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 39

Expert Comment

by:gdemaria
ID: 36582792
Your goal is just to create a directory if it doesn't exist?  given that the creation may involve multiple levels..

 did you ever try this?  I wonder if the command will create multiplevels at once?

<cfset pathToCreate = "testClient/iEnvelopes">
 
<cfset DirectoryTree = expandPath("/") & pathToCreate>
 <cfif NOT DirectoryExists(DirectoryTree)>
      <cfdirectory action="Create" directory="#DirectoryTree#">
 </cfif>
     

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 36582798
If not, here's another version of the code you provided.  I'm having trouble following all the variables, but I think this is all you need... just loop through the relative path, adding the root directory, and create each one...


<cfset pathToCreate = "testClient/iEnvelopes">
<cfset rootDirectory = expandPath("/")>
 
<cfloop index="Directory"  list="#pathToCreate#"  delimiters="\/">
       <cfset DirectoryTree = ListAppend(rootDirectory,Directory,"\")>
     <cfif NOT DirectoryExists(DirectoryTree)>
        <cftry>
        <cfdirectory action="Create" directory="#DirectoryTree#">
         <cfcatch>
              <!--- Just let it loop --->
         </cfcatch>
         </cftry>
     </cfif>
</cfloop>

0
 
LVL 1

Author Comment

by:Shawn
ID: 36582841
>>I wonder if the command will create multiplevels at once?

I tried and it didn't work. found the loop in another ee solution.

just checking your other suggestion. It looks cleaner in any case
0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 36583195
thx again gdemaria.

if you have seen the bug on Q_27322793 before feel free to jump in. agx and I are scratching our heads.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now