Solved

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

Posted on 2011-09-21
8
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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
 
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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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