Custom Image Upload Folders - Row_Inserting Event

Tips submitted by ASP.NET Maker users

Custom Image Upload Folders - Row_Inserting Event

Postby xgis » Sat Nov 09, 2013 9:01 am

This code is related to post "Advanced Auto-Update Code to get Next Unique ID".
A common issue with image uploading to a single folder is that most images generated by capture devices such as cameras restart their "unique" names every time a card is formatted.
Inevitably images named like image1.jpg, will become image1(1).jpg, image1(2).jpg etc. in the ANM10 image folder management system.
The database and code will manage this fine but it tends to get messy in terms of row based file management.

It is critical to note that this is the Primary post for initiation of a Custom Folder Management Solution.
Other posts will target the remaining events and considerations with a goal to utilise existing ANM10 infrastructure such as "Keep, Remove, Replace" radio button functionality for EDIT and Update events.
It is important to note some fundamental edits of the template may be required to resolve two primary issues of physical path vs relative path for image row display as well as dealing with upload limitations to increase the maximum file size from 4Mb to at least 100Mb.
It is also critical to note that this first part of the process is for development, as default ANM10 controls will not be able to "locate" these images for EDITS and updates or deletes. Subsequent posts aim to resolve these inevitable issues.

This code below will enable you to insert an image into a custom folder.
It also renames the image and stores the original and new filenames in the database.
It works but has no error handling as yet.

// Row Inserting event
public bool Row_Inserting(OrderedDictionary rsold, ref OrderedDictionary rsnew) {
string folderpath = null;
folderpath = "App_Data_Sites/" + SiteIDMax() + "/"; //This utilises code from another post "Advanced Auto-Update Code to get Next Unique ID"
//HttpContext.Current.Response.Write(folderpath); //This is used for development to see what paths are being generated...
if (Image1 != null)
{ Image1.UploadPath = folderpath;
string fileName = null;
fileName = Convert.ToString(rsnew["Image1"]);
rsnew["Image1OriginalName"] = fileName; //store the original filename in the DB field
string ext = System.IO.Path.GetExtension(fileName).ToLower(); //get the filetype extension to add as a suffix to the newly generated filename stored in the DB
string newimagename = "Site_" + SiteIDMax() + "_Image1_SiteMap"; //generate the new unique filename based on the folder name and other variables
rsnew["Image1"] = newimagename + ext; //store the name in the DB field
} else { return false;
} return true;
}
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm

Re: Custom Image Upload Folders - Row_Inserting Event

Postby xgis » Sat Nov 09, 2013 8:34 pm

PART II: Image Display: BASIC Image Display from Custom Folder Using Row_Rendered Event

It is important to NOTE that this does NOT resolve HREF field issues. Therefore you cannot click on the image and make it display in the browser.
Yet to be resolved are are "Relative Path - Physical Path" defaults used by ANM10.
The objective of these posts is to identify a method to override WITHOUT modifying the template.

It ONLY displays the image from the custom folder. It does NOT display a thumbnail like Default.
Uploaded TIF images do not display but JPG's do.

The CODES;

// Row Rendered event
public void Row_Rendered() {
string folderpath;

if (Image1.Upload.DbValue != null)
{
folderpath = "App_Data_Sites/" + SiteID.DbValue + "/";
Image1.ViewValue = folderpath + Image1.Upload.DbValue;
HttpContext.Current.Response.Write(Image1.ViewValue);
}
else
{
Image1.ViewValue = "";
}
}
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm

Re: Custom Image Upload Folders - Row_Inserting Event

Postby xgis » Mon Nov 11, 2013 2:59 pm

Part III: The Codes Outlined below do Two different things;
1: Enable HREF support for files located in custom folders
2: Disable the use of filename suffixes where files of the same name are uploaded.

1. Update To Code for Row_Rendered
This line will enable display of the Image in the Browser window when clicked.
Image1.HrefValue = Image1.ViewValue;
Also comment out the following like so //HttpContext.Current.Response.Write(Image1.ViewValue);
It is only used in development to display the values at the top of the screen

2. Prevent ANM10 from Creating Uploads with "(#)" numbers for repeated filenames
Important: Advanced (Warning - Permanent) : Requires Template Modification (In this example)
Be aware also that this process may result in overwriting of filenames for projects storing files in the default single folder scenario

Open the template file aspx102.zip. Locate the file aspxfn.cs.
With UAC control you will need to edit and update these files outside of the default folder.
Open the "aspxfn.cs" file. Navigate to "ew_UniqueFileName" and then to line 6242 which displays "return Name + Suffix + Ext;"
Remove "+ Suffix" to look like this;
return Name + Ext;
That is all that needs to be done for the coding.

Save aspxfn.cs Update the file in template file aspx102.zip.
Relocate the zip to Default ANM10 install location template folder.
Generate your project. Press the "Overwrite" button to use the modified template in your next project generation.
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm


Return to User Submited Tips (ASP.NET Maker)