Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Configure where the upload are placed

C#

 

  1. Open the web.config file, and correctly configure the folder where the uploaded files will be placed:

    Code Block
    languagexml
    titleweb.config upload path configuration
      <appSupportLibSettings 
    	 ... 
         uploadPath="~/uploadDropZone/" />
    Info
    titleNote:

    If using the upload handler present on the Foundations Framework, the developer needs to create specified folder on the server in order for the handler to correctly save the file. The handler doesn't create server folders if they are not found!

  2. Open the config.xml file and set the UPLOAD_URL global parameter with the FileUploadHandler.ashx file path:

    Code Block
    languagexml
    titleconfig.xml upload_url parameter configuration
    <param name="UPLOAD_URL" value="/<server_path>/FileUploadHandler.ashx" />
  3. Prepare the server-side action to process the uploaded file. Here's an example of the code you could use to either process a single file or a zip with multiple files to process:

    Code Block
    languagec#
    titleProcessUploadedFile method
    public virtual void ProcessUploadedFile()
    {
    	try
    	{
    		String uploadedDropZone = Foundations.Core.AppSupportLib.Configuration.AppSupportLibSettings.GetConfig().UploadPath;
    		String uploadedFile = System.Web.HttpContext.Current.Request.MapPath(uploadedDropZone) + Model.BlockName.ItemName;
     
    		if (File.Exists(uploadedFile))
    		{
    			IList<string> files2Process = null;
     
    			if (uploadedFile.ToLower().EndsWith(".zip"))
    				files2Process = UnzipFile(uploadedFile);
    			else
    				files2Process = new List<string>() { uploadedFile };
     
    			foreach (string file in files2Process)
    			{
    				// process the file's contents
    			}
    		}
    	}
    }
    Info
    titleNote:

    This code assumes that if the user uploads a zip file, it's contents should be unzipped into a list of files to process.

...