%@ Language=VBScript %>
<% Option Explicit %>
<%
'-------------------------------------------------------------------------
' folder_new.asp : This page serves in creating a new folder
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Date Description
' 17-01-2001 Creation date
' 21-03-2001 Modified date
'-------------------------------------------------------------------------
%>
<%
'-------------------------------------------------------------------------
' Global Variables
'-------------------------------------------------------------------------
Dim rc 'Page variable
Dim page 'Page variable
Dim g_iTabGeneral 'Variable for General tab
Dim g_iTabCompress 'Variable for Compress tab
Dim SOURCE_FILE 'File name
SOURCE_FILE = SA_GetScriptFileName()
'-------------------------------------------------------------------------
' Form Variables
'-------------------------------------------------------------------------
Dim F_strCompressed 'Value of Compress Checkbox
Dim F_strParentFolderName 'Parent folder name
Dim F_strReadOnly 'Status of Readonly Checkbox
Dim F_strHidden 'Status of Hidden Checkbox
Dim F_strArchive 'Status of Archive Checkbox
Dim F_strChangeOption 'Status of radio button for compression of folder
Dim F_strFolderCompress 'Value of radio button to compress folder
Dim F_strFolderName 'Folder name
Dim F_strPathName 'Folder path
'------------------------------------------------------------------------
'Localization Variable and Constants
'------------------------------------------------------------------------
Dim L_PAGETITLE_NEW_TEXT 'Page title
Const CONST_ARR_APPLYALLFOLDERS = "ALL"
Const CONST_ARR_APPLYFOLDER = "ONE"
Const CONST_N_SIZEDATA_TEXT = "0"
Const CONST_UNCHECKED_TEXT = "UNCHECKED"
Const CONST_CHECKED_TEXT = "CHECKED"
'Page Title
L_PAGETITLE_NEW_TEXT = L_TABLEHEADING_TEXT 'Here the parent folder name must be appended
'Create a Tabbed Property Page
rc = SA_CreatePage(L_PAGETITLE_NEW_TEXT, "", PT_TABBED, page )
'Add two tabs
rc = SA_AddTabPage( page, L_GENERAL_TEXT, g_iTabGeneral)
rc = SA_AddTabPage( page, L_COMPRESS_TEXT, g_iTabCompress)
'Show the page
rc = SA_ShowPage( page )
'-------------------------------------------------------------------------
'Function name: OnInitPage
'Description: Called to signal first time processing for this page.
'Input Variables: PageIn,EventArg
'Output Variables: PageIn,EventArg
'Returns: TRUE to indicate initialization was successful. FALSE to indicate
' errors. Returning FALSE will cause the page to be abandoned.
'Global Variables: Out:None
' In: None
'--------------------------------------------------------------------------
Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
Call SA_TraceOut(SOURCE_FILE, "OnInitPage")
F_strParentFolderName = replace(Request.QueryString("parent"),"/","\")
'Setting Folder Compress property to parent folder by default
F_strFolderCompress = CONST_ARR_APPLYFOLDER
Call SA_MungeURL(mstrReturnURL, "PKey", replace(F_strParentFolderName, "\", "/"))
OnInitPage = TRUE
End Function
'-------------------------------------------------------------------------
'Function name: OnPostBackPage
'Description: Called to signal that the page has been posted-back.
'Input Variables: PageIn,EventArg
'Output Variables: PageIn,EventArg
'Returns: TRUE to indicate initialization was successful. FALSE to indicate
' errors. Returning FALSE will cause the page to be abandoned.
'Global Variables: F_(*), L_(*)
'--------------------------------------------------------------------------
Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
Call SA_TraceOut(SOURCE_FILE, "OnPostBackPage")
'Updating the form variables
F_strFolderName = Trim(Request.form("txtNewFolderName"))
F_strCompressed = Request.Form("chkCompress")
F_strFolderCompress = Request.Form("radFolders")
F_strHidden = Request.Form("chkHidden")
F_strReadOnly = Request.Form("chkReadOnly")
F_strArchive = Request.Form("chkArchive")
F_strParentFolderName = Request.Form("hdnParentFolder")
If F_strFolderCompress = CONST_ARR_APPLYALLFOLDERS Then
F_strChangeOption = Ucase(CONST_CHECKED_TEXT)
Else
F_strChangeOption = UCase(CONST_UNCHECKED_TEXT)
End if
OnPostBackPage = TRUE
End Function
'-------------------------------------------------------------------------
'Function name: OnServeTabbedPropertyPage
'Description: Called when the page needs to be served.
'Input Variables: PageIn,EventArg
'Output Variables: PageIn,EventArg
'Returns: TRUE to indicate initialization was successful. FALSE to indicate
' errors. Returning FALSE will cause the page to be abandoned.
'Global Variables: None
'--------------------------------------------------------------------------
Public Function OnServeTabbedPropertyPage(ByRef PageIn, _
ByVal iTab, _
ByVal bIsVisible, ByRef EventArg)
'Emit content for the requested tab
Select Case iTab
Case g_iTabGeneral
Call ServeTabGeneral(PageIn, bIsVisible)
Case g_iTabCompress
Call ServeTabCompress(PageIn, bIsVisible)
Case Else
Call SA_TraceOut(SOURCE_FILE, "OnServeTabbedPropertyPage")
End Select
OnServeTabbedPropertyPage = TRUE
End Function
'-------------------------------------------------------------------------
'Function name: OnSubmitPage
'Description: Called when the page has been submitted for processing.
'Input Variables: PageIn,EventArg
'Output Variables: PageIn,EventArg
'Returns: TRUE if the submit was successful, FALSE to indicate error(s).
' Returning FALSE will cause the page to be served again using
' a call to OnServePropertyPage.
'Global Variables: None
'--------------------------------------------------------------------------
Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
'Call CreateNewFolder function to create new folder
OnSubmitPage = CreateNewFolder
End Function
'-------------------------------------------------------------------------
'Function name: OnClosePage
'Description: Called when the page is about to be closed.
'Input Variables: PageIn,EventArg
'Output Variables: PageIn,EventArg
'Returns: TRUE to allow close, FALSE to prevent close. Returning FALSE
' will result in a call to OnServePropertyPage.
'Global Variables: Out:None
' In: None
'--------------------------------------------------------------------------
Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
OnClosePage = TRUE
End Function
'-------------------------------------------------------------------------
'Function name: ServeTabGeneral
'Description: Serves in selecting the tab1
'Input Variables: PageIn,bIsVisible
'Output Variables: PageIn
'Returns: None
'Global Variables: gc_ERR_SUCCESS,F_strFolderName,F_(*),L_(*)
'--------------------------------------------------------------------------
Function ServeTabGeneral(ByRef PageIn, ByVal bIsVisible)
If ( bIsVisible ) Then
'ServeCommonJavaScriptGeneral is called for General tab initialising,validating and set data
Call ServeCommonJavaScriptGeneral()
%>
<%=L_FOLDERNAME_TEXT%>
<%=L_FOLDERTYPE_TEXT %>
<%=L_TYPE_TEXT%>
<%=L_FOLDERLOCATION_TEXT %>
<%=server.HTMLEncode(F_strParentFolderName)%>
<%=L_FOLDERSIZE_TEXT %>
<%=CONST_N_SIZEDATA_TEXT%>
<%=L_FOLDERCONTAINS_TEXT%>
<%=L_CONTAINSDATA_TEXT%>
<%=L_FOLDERCEATED_TEXT%>
<%=L_FOLDERATTRIBUTE_TEXT%>
><%=L_READONLY_TEXT%>
><%=L_HIDDEN_TEXT%>
><%=L_ARCHIVING_TEXT%>
<%
Else
%>
<%
End If
End Function
'-------------------------------------------------------------------------
'Function name: ServeTabCompress
'Description: Serves in selecting the tab2
'Input Variables: PageIn,bIsVisible
'Output Variables: PageIn
'Returns: None
'Global Variables: F_(*),L_(*),gc_ERR_SUCCESS,F_strFolderName
'--------------------------------------------------------------------------
Function ServeTabCompress(ByRef PageIn, ByVal bIsVisible)
If ( bIsVisible ) Then
'ServeCommonJavaScriptCompress is called for Compress tab initialising,validating and set data
Call ServeCommonJavaScriptCompress()
%>
<%=L_FOLDER_TEXT %>
<% if instr(F_strParentFolderName,"\")=len(F_strParentFolderName) then
Response.write Server.HTMLEncode(F_strParentFolderName) & Server.HTMLEncode(F_strFolderName)
else
Response.write Server.HTMLEncode(F_strParentFolderName) & chr(92) & Server.HTMLEncode(F_strFolderName)
end if%>
> <%=L_COMPRESSCONTENTS_TEXT%>
<%=L_APPLYCHANGES_TEXT%>
> <%=L_APPLYCHANGES_EX_TEXT%>
<%
Else
%>
<%
End If
End Function
'-------------------------------------------------------------------------
'Function name: ServeCommonJavaScriptGeneral
'Description: Common javascript functions that are required by the General tab
'Input Variables: None
'Output Variables: None
'Returns: None
'Global Variables: None
'--------------------------------------------------------------------------
Function ServeCommonJavaScriptGeneral()
%>
<%
End Function
'-------------------------------------------------------------------------
'Function name: ServeCommonJavaScriptCompress
'Description: Common javascript functions that are required by the Compress tab
'Input Variables: None
'Output Variables: None
'Returns: None
'Global Variables: None
'--------------------------------------------------------------------------
Function ServeCommonJavaScriptCompress()
%>
<%
End Function
'-------------------------------------------------------------------------
'Function name: CreateNewFolder
'Description: Creating the new folder and assigning the properties
'Input Variables: None
'Output Variables: None
'Returns: (True / Flase )
'Global Variables: F_strParentFolderName,F_strFolderName,L_(*)
'--------------------------------------------------------------------------
Function CreateNewFolder
On Error Resume Next
Err.Clear
Dim strFolderPath 'Folder path
Dim objFolder 'File system object
Dim strFolderExists 'To get the folder
Dim objConnection 'Object to get WMI connection
Dim objFolderProp 'To get the folders properties
Dim objDirInstances 'Collection to get Instances of Win32_Directory class
Dim objDirInstance 'Object to get Instance of Win32_Directory class
Dim strQuery
Const CONST_N_DEVICENOTREADY_ERRNO = 71 'Error number incase derive is not ready
Const CONST_N_FOLDER_READ_ATTRIBUTE = 1 'Constant for folder read attribute
Const CONST_N_FOLDER_HIDDEN_ATTRIBUTE = 2 'Constant for folder hidden attribute
Const CONST_N_FOLDER_ARCHIVE_ATTRIBUTE = 32 'Constant for folder archive attribute
Call SA_TraceOut(SOURCE_FILE, "CreateNewFolder")
CreateNewFolder= FALSE
'Folder path
If right(F_strParentFolderName,1) = chr(92) then
'If parent folder path is already having "\" donot append the "\"
strFolderPath= F_strParentFolderName & F_strFolderName
Else
'If parent folder path donot have "\" append the "\"
strFolderPath= F_strParentFolderName & chr(92) & F_strFolderName
End If
'Create File System Object
Set objFolder = createobject("scripting.FileSystemObject")
If Err.number <> 0 Then
Call SA_SetErrMsg (L_FILESYSTEMOBJECTNOTCREATED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")" )
Exit Function
End If
'Checking if the folder already exists
If Not objFolder.FolderExists(strFolderPath) Then
CreateNewFolder = TRUE
'Creating the new folder
objFolder.CreateFolder(strFolderPath)
If Err.Number <> 0 Then
If Err.number= CONST_N_DEVICENOTREADY_ERRNO Then
Call SA_SetErrMsg (L_DEVICEISNOTREADY_ERRORMESSAGE & "(" & Err.Number & ")" )
CreateNewFolder = FALSE
Exit Function
Else
Call SA_SetErrMsg (L_DIRECTORYNOTCREATED_ERRORMESSAGE & "(" & Err.Number & ")" )
CreateNewFolder = FALSE
Exit Function
End If
End If
'Get the specified folder
Set objFolderProp = objFolder.GetFolder(strFolderPath)
'Set the Read Only attributes
If trim(F_strReadOnly)= trim(CONST_CHECKED_TEXT) Then
objFolderProp.attributes =objFolderProp.attributes + CONST_N_FOLDER_READ_ATTRIBUTE
End If
'Set the Hidden attribute
If trim(F_strHidden)= trim(CONST_CHECKED_TEXT) Then
objFolderProp.attributes =objFolderProp.attributes + CONST_N_FOLDER_HIDDEN_ATTRIBUTE
End If
'Set the Archives attribute
If trim(F_strArchive)= trim(CONST_CHECKED_TEXT) Then
objFolderProp.attributes = objFolderProp.attributes + CONST_N_FOLDER_ARCHIVE_ATTRIBUTE
End If
'Create connection to WMI
Set objConnection = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
'Create instance of Win32_Directory
strQuery = "Select * from Win32_Directory where Name = " & chr(34) & replace(strFolderPath, "\", "\\") & chr(34)
Set objDirInstances = objConnection.ExecQuery(strQuery)
'Failed to connect to WMI
If Err.Number <> 0 Then
Call SA_ServeFailurepage (L_WMICONNECTIONFAILED_ERRORMESSAGE & " " & Hex(Err.Number))
CreateNewFolder = FALSE
Exit Function
End if
For each objDirInstance in objDirInstances
'Set the compress property of folder
If UCase(F_strCompressed) = trim(Ucase(CONST_CHECKED_TEXT)) then
if F_strFolderCompress = CONST_ARR_APPLYFOLDER then
objDirInstance.UnCompressEX null,null,True
objDirInstance.CompressEX null,null,False
elseif F_strFolderCompress = CONST_ARR_APPLYALLFOLDERS then
objDirInstance.UnCompressEX null,null,False
objDirInstance.CompressEX null,null,True
end if
End if
Exit for
Next
Set objDirInstance= Nothing
Set objConnection = Nothing
Else
Call SA_SetErrMsg (L_DIRECTORYALREADYEXISTS_ERRORMESSAGE & "(" & Hex(Err.Number) & ")" )
Exit Function
End If
'Release the objects
Set objFolderProp = Nothing
Set objFolder = Nothing
End Function
%>