Custom Upload Outside Application using Virtual Directories

Tips submitted by ASP.NET Maker users

Custom Upload Outside Application using Virtual Directories

Postby xgis » Mon Nov 11, 2013 7:27 pm

To overcome the issue of uploading ABOVE the APPLICATION ROOT Folder is very simple if you use Virtual Directories in IIS.
This example is created based on the ANM10 Generated Website being Nested in another website.
The reason for this is it gives me somewhere to put folders and files so I do not risk accidentally generating over my folders and files.
It also helps me to maintain a single folder in WWWROOT for all Website related tasks.
It is also a good place to store sensitive files such as the AGX which should NOT be located in the published website folder.

Related Posts:
Custom Image Upload Folders - Row_Inserting Event - viewtopic.php?f=45&t=33634
Increase Image - File Uploads to 100Mb - viewtopic.php?f=45&t=33638

The Goals:
1. Store Files in Folders Above the Application Root Folder; e.g. C:\inetpub\wwwroot\MainWebsite\YourCustomVDUploadFolder\
2. Manage Files elsewhere using a Virtual Directory in IIS here; e.g. C:\inetpub\wwwroot\MainWebsite\ANM10WebsiteAppRoot\
3. Enable complete site regeneration without risk of losing existing folder based data.
4. Cleaner, safer and faster delivery of presentation application eg ASP.NET
5. Static safe folder for server scheduled backups of data eg using BAT files etc

All code will be directed at the Virtual directory but all files will actually live in the physical folder above the application root.
There is need to even create the folder. If you do and you always regenerate using "Clear All" you would have to manually create it each time or code it to autogenerate.

1. Windows Explorer: Create this folder; e.g. C:\inetpub\wwwroot\MainWebsite\YourCustomVDUploadFolder"
2. IIS: Click on this folder e.g. C:\inetpub\wwwroot\MainWebsite\ANM10WebsiteAppRoot\
3. Right click to create the Virtual Directory folder e.g. "YourCustomVDUploadFolder" which simply points to the physical folder that in this case is one folder above the Application Root.

This is NOT limited to this structure or location, but the example was based only on my immediate needs.
Maybe you have an existing or separate website where the files need to be made available e.g D or E etc.
This is NOT limited to custom uploads referred to in the posts above. The same should be possible for standard ANM10 file upload to folder based projects.
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm

Re: Display PDF and Other Uploads from Virtual Directories

Postby xgis » Fri Dec 06, 2013 8:23 pm

Once you have placed data into folders that are located using virtual directories it is possible to display and access those values through ANM10.
In the case of a PDF file which can be opened in the browser, or a CSV file that can be opened by Excel or images etc.
It is important to note that the relative path must be referenced properly for the file to be "visible" by the generated ANM10 web application.

This example uses an MSSQL View (aka query) to simply list the name of the FILE from the original FILE UPLOAD field.
We then create a 'folderpath' so it knows where to look for that FILE.

In the original table the "Upload folder" is written like this "/FLPDBUploads/FLPD1TransactionReportFileName/"
"FLPDBUploads" is the Virtual Directory Root Folder
"FLPD1TransactionReportFileName" is the name of the Table Field. (In the View/Query for this example the UPLOAD field name has been changed to something more meaningful like "LatestReport")

The required event is Row_Rendered.
This example uses the HREF value for the UPLOAD field and the Target is set to '_blank' so a new browser TAB opens.
It uses the "ViewValue" to get the actual filename that has been loaded into that folder and stored in the database table.

// Row Rendered event (Actual Example)
public void Row_Rendered() {
string folderpath = "/FLPDBUploads/FLPD1TransactionReportFileName/";
LatestReport.HrefValue = folderpath + LatestReport.ViewValue;
}

// Row Rendered event (Generic Example)
public void Row_Rendered() {
string folderpath = "/<RootVDFolderName>/<UPLOADFieldName>/";
<VIEWFieldName>.HrefValue = folderpath + <VIEWFieldName>.ViewValue;
}
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm


Return to User Submited Tips (ASP.NET Maker)