close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

create the image filename as the ID

Thread began 8/09/2009 4:07 pm by Carl | Last modified 8/21/2009 1:19 am by karen.marley367377 | 3829 views | 10 replies |

Carl

create the image filename as the ID

Hi

I have a insert form and it has categories field and a file field. When I click the Insert button I want the name of the file that is being uploaded to be the id of the record the form is inserting into the database.

Can this be done? or do I need to insert the record first and then the image on a separate page?

Thanks

Carl

Sign in to reply to this post

Jason ByrnesWebAssist

The record will need to be created before the image is uploaded. by default, digital file pro will add the upload code before the Insert record code so that the name of the uploaded file can be inserted into the file name column of the database.

If you are using the DataAssist insert record server behavior, a session variable is created with the ID of he record that was inserted.

The name of the session variable is set in the Session section of the DataAssist insert record server behavior. In the DFP Upload File Wizard, you could reference the session variable as the file name, but you will need to Manually move the Upload code to be after the Insert Record server behavior, and make sure that the insert record server behavior does not specify a page to redirect to after the record is inserted.

Sign in to reply to this post

karen.marley367377

Create the image filename as the ID

Hi Jason, I too would like to name the image the same as the record ID. I have followed this post and moved the upload behaviour to after the insert record behaviour, name the file name as the session id, but get the following error message
Microsoft JScript runtime error '800a138f'

'WA_DFP_UploadStatus.WA_UploadResult1.serverFileName' is null or not an object

/Properties_Insert4.asp, line 131 - This is set in the insert record server behaviour (as on the solution recipe).

// WA Application Builder Insert
if (String(WA_DFP_UploadObj.Form("Insert.x")) != "undefined") {
var WA_connection = MM_blanug439_STRING;
var WA_table = "Properties";
var WA_sessionName = "Properties_MainPropertiesID";
var WA_redirectURL = "";
var WA_keepQueryString = false;
var WA_indexField = "MainPropertiesID";
var WA_fieldNamesStr = "FirstName|LastName|Company|PropertyType|SaleORLease|RegionName|Address1|Address2|City|County|PostCode|Country|Thumb|AgentLogo|PropertyDetails|Size|Sep|SizeMax|SizeType|shortDescription|longdescription|Price|Status";
var WA_fieldValuesStr = "" + String((WADAMembers.Fields.Item("FirstName").Value)) + "" + "|" + "" + String((WADAMembers.Fields.Item("LastName").Value)) + "" + "|" + "" + String((WADAMembers.Fields.Item("Company").Value)) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("PropertyType")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("SaleORLease")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("RegionName")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Address_1")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Address2")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("City")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("County")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("PostCode")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Country")) + "" + "|" + "" + String(WA_DFP_UploadStatus["WA_UploadResult1"].serverFileName) + "" + "|" + "" + String((WADAMembers.Fields.Item("AgentLogo").Value)) + "" + "|" + "" + String(WA_DFP_UploadStatus["WA_UploadResult2"].serverFileName) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Size")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Separator")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("SizeMax")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("SizeType")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("shortDescription")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("longdescription")) + "" + "|" + "" + String(WA_DFP_UploadObj.Form("Price")) + "" + "|" + "Awaiting Approval";
var WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|none,none,NULL|',none,''|none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''";
var WA_comparisonStr = " LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | LIKE | = | LIKE | = | LIKE | LIKE | LIKE | LIKE | LIKE ";
var WA_fieldNames = WA_fieldNamesStr.split("|");
var WA_fieldValues = WA_fieldValuesStr.split("|");
var WA_columns = WA_columnTypesStr.split("|");
var WA_comparisons = WA_comparisonStr.split("|");
var insertParamsObj = WA_AB_generateInsertParams(WA_fieldNames, WA_columns, WA_fieldValues);
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = WA_connection;
MM_editCmd.CommandText = "INSERT INTO " + WA_table + " (" + insertParamsObj.WA_tableValues + ") VALUES (" + insertParamsObj.WA_dbValues + ")";
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
var obj = WA_AB_generateWhereClause(WA_fieldNames, WA_columns, WA_fieldValues, WA_comparisons);
var sqlstr = "SELECT " + WA_indexField + " FROM " + WA_table + " WHERE " + obj.sqlWhereClause + " ORDER BY " + WA_indexField + " DESC";
var WA_AppBuilderRecordset = Server.CreateObject("ADODB.Recordset");
WA_AppBuilderRecordset.ActiveConnection = WA_connection;
WA_AppBuilderRecordset.Source = sqlstr;
WA_AppBuilderRecordset.CursorType = 0;
WA_AppBuilderRecordset.CursorLocation = 2;
WA_AppBuilderRecordset.LockType = 1;
WA_AppBuilderRecordset.Open();
if (!WA_AppBuilderRecordset.EOF) {
Session(WA_sessionName) = WA_AppBuilderRecordset.Fields.Item(WA_indexField).Value;
}
WA_AppBuilderRecordset.Close();
if (WA_redirectURL != "") {
if (WA_keepQueryString && WA_redirectURL != "" && Request.QueryString && Request.QueryString.Count > 0) {
WA_redirectURL += ((WA_redirectURL.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
Response.Redirect(WA_redirectURL);
}
}
%>
<%
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(WA_DFP_UploadStatus["WA_UploadResult1"].statusCode == 1){
WA_DFP_UploadFile("WA_UploadResult1", "Thumb", "userfiles/Thumbs/noimage.jpg", "userfiles/Thumbs/", "" + String( Session("Properties_MainPropertiesID") ) + "", "2", "[FileName]_[Increment]", "1024", "false", "0", "0");
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Sign in to reply to this post

Jason ByrnesWebAssist

This is because you are trying to store the image in the record using the insert record server behavior, since the insert record server behavior happens first, the image has not been uploaded yet to set the server file name.


In actual fact, since the image is being given record ID as the name, there is no reason to store the file name in the database. you can refer to the ID column of the database to get the images name.

Sign in to reply to this post

karen.marley367377

Thanks Jason, I have referenced the Digi Pro to Name file as Session ID and the insert record field as Table ID. The file uploads to the server and the image record stores as the correct table id MINUS the file extension - i.e. 1234 instead of 1234.jpg. Therefore in the Results Page the image cannot be viewed. How do I store it has the tableid plus the file extension so the result page shows the image?

Sign in to reply to this post

Jason ByrnesWebAssist

add the extesnion .jpg in the file name box after the code for the session variable. So if the code in the fiole name box is:

<%= String(Session("Properties_MainPropertiesID")) %>




change it to:

<%= String(Session("Properties_MainPropertiesID")) %>.jpg

Sign in to reply to this post

karen.marley367377

Thanks Jason,

The files uploaded also include gifs and bitmaps...

Sign in to reply to this post

Jason ByrnesWebAssist

One of the variables created by DFP is the file extesnion.


For the file name, click the lightning bolt and expand the WA upload Files (File Field name) Group and select the File Extesnion binding.

Then paste:
<%= String(Session("Properties_MainPropertiesID")) %>. before the code that is added.

Sign in to reply to this post

karen.marley367377

How to Reference on the Results Page

Hi Jason, Thank you for your help. The file uploads fine but cannot work out how to reference this on the results page, tried referencing the image field to the session variable for the Page_Image, now all the results show the same image. Any ideas?

Many thanks

Sign in to reply to this post

Jason ByrnesWebAssist

since you are using multiple file extensions, In your database, you will need to store either the file extension by using the File extension binding, or the server file name.

You will need to use an update record server behavior for this, and make sure that the code for the update is placed after the Insert Record code.


In the update record server behavior, set the ID column to filter on the Properties_MainPropertiesID session variable to update the correct record.

Then on the results page, get the file name from the recordset.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...