<%
' *****************************************************************************
' File:		/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/
'			ResourceBrowser/Management/ResourceFileIO.inc
'
' Author:	Microsoft Corporation.
' Purpose:	Contain the functions used by the file uploading process
'
' *************************************************************************************


Dim g_pResMgtFormReader
Set g_pResMgtFormReader = Nothing

' ---- [Public] Initialize the NCASPExtensions.ASPFormReader object for form reading and display any errors
Function GetResMgntFormReaderSafe( bUploadValidate, lCodePage )
	Err.Clear()
	On Error Resume Next
	
	
	' -- If the form reader has already been initialized, then return the existing reader.
	If Not g_pResMgtFormReader Is Nothing Then
		Set GetResMgntFormReaderSafe = g_pResMgtFormReader
		Exit Function
	End If
	
	' -- Create the ASPFormReader object
	Set g_pResMgtFormReader = Server.CreateObject("NCASPExtensions.ASPFormReader")

	' -- set the form reader CodePage and UploadValidation flags according to parameters
	g_pResMgtFormReader.CodePage = lCodePage
	g_pResMgtFormReader.UploadValidation = bUploadValidate
	
	Set GetResMgntFormReaderSafe = g_pResMgtFormReader
End Function

' ---- [Public] Functions to accept binary upload from client, and return the resulting file name
Function AcceptFileUpload( pFormReader, strFormFieldName )
	Err.Clear()
	On Error Resume Next

	' figure out where to create the temporary file
	Dim strUploadTempDir


	AcceptFileUpload = ""
	strUploadTempDir = GetSCAUpLoadDirectory()
	If (Err.Number <> 0) Then
		Exit Function
	End If


	' the mime type suggested by the user
	Dim strSuggestedMime
	strSuggestedMime = pFormReader.Form("NC_Mime")

	' get NCASPFormReader to accept file, which will create a file in the server
	Dim strTempFileName
	strTempFilename = pFormReader.Files(strFormFieldName).Save( strUploadTempDir, strSuggestedMime )

	' return the fileName
	AcceptFileUpload = strTempFileName
End function

' ---- [Public] Cleanup stream of data left in the Request.BinaryRead()
Sub CleanupRequestStream()
	Dim varContent
	While (True)
		Dim nCount
		nCount = 100000
		varContent = Request.BinaryRead(nCount)
		If (nCount = 0) Then
			Exit Sub
		End If
	Wend
End Sub

%>