Forums: Rename Uploaded Files - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Rename Uploaded Files Rate Topic: -----

#1 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 31 October 2017 - 05:11 PM

I currently have a page where users can upload multiple files with different extensions at once. I would like to use the following naming convention "Unique_ID" + "Name" + "_XX" + extension; Where "Unique_ID" and "Name" are fields in the form, "_XX" is the number of the file, and extension is well... the extension.

For example: John Smith opens a new new form and its automatically assigned Unique_ID number 857, he then proceeds to upload files ashdkhsa.pdf, 546asw.doc, and jshh232h_64.jpg. The files should be renamed 857_JohnSmith_01.pdf, 857_JohnSmith_02.doc, and 857_JohnSmith_03.jpg respectively.

ashdkhsa.pdf = 857_JohnSmith_01.pdf
546asw.doc = 857_JohnSmith_02.doc
jshh232h_64.jpg = 857_JohnSmith_03.jpg


I already looked at this page but I'm not sure how to obtain the extension for each individual file, or how to add the file number.

Thank you!
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16112
  • Joined: 03-February 03
  • Gender:Male

Posted 31 October 2017 - 08:36 PM

You can see the code that shows how to rename files at https://xlinesoft.co...oaded_files.htm To find a file extension you need to parse the file name, find the last dot and everything after that dot will be your extension.

The only flaw here is that this code normally to be placed to BeforeAdd/BeforeEdit events where your Unique ID number is not generated yet. Typically autoincrement number are generated by the database when record is added and not before that.
Best regards,
Sergey Kornilov
0

#3 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 31 October 2017 - 08:58 PM

View Postadmin, on 31 October 2017 - 12:36 PM, said:

You can see the code that shows how to rename files at https://xlinesoft.co...aded_files.htm. To find a file extension you need to parse the file name, find the last dot and everything after that dot will be your extension.

The only flaw here is that this code normally to be placed to BeforeAdd/BeforeEdit events where your Unique ID number is not generated yet. Typically autoincrement number are generated by the database when record is added and not before that.


I cant connect to that page, I get a 404 error. But I assume is the same page I meant to link on my original post but forgot. https://xlinesoft.co...oaded_files.htm

View Posti.NoLim, on 31 October 2017 - 09:11 AM, said:

I already looked at this page


I tried using that code but I get the following error.

Quote

error CS0131: The left-hand side of an assignment must be a variable, property or indexer


And this code could not be added in the "After record added" event?

Edit: I managed to open the link using a different browser, will post when I have updates.
0

#4 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16112
  • Joined: 03-February 03
  • Gender:Male

Posted 31 October 2017 - 10:30 PM

If you getting an error message that means you doing something wrong. This code is tested and works.

It is also possible to implement a similar technique in events like AfterAdd and AfterEdit. Instead of assigning a value to values("fieldname") you will need to build and execute a SQL query that updates "fieldname" field in the database.
Best regards,
Sergey Kornilov
0

#5 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 31 October 2017 - 10:42 PM

I've never actually used VB so I'm having some issues with the code. I understand its grabbing the names of the files uploaded and storing them in an array. It then uses a for loop to go into the array, grabs each individual file and renames it. I'm not entirely sure what's going on in lines 31 and 32, it seems like its moving the file? Line 38 updates the value in the DB.

https://imgur.com/vWgGILc

https://imgur.com/a/jBPM6
0

#6 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 31 October 2017 - 11:01 PM

View Postadmin, on 31 October 2017 - 02:30 PM, said:

If you getting an error message that means you doing something wrong. This code is tested and works.

It is also possible to implement a similar technique in events like AfterAdd and AfterEdit. Instead of assigning a value to values("fieldname") you will need to build and execute a SQL query that updates "fieldname" field in the database.

That makes sense but will this change the name of the actual file or just the name that is displayed, as mentioned in the link you provided.
0

#7 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16112
  • Joined: 03-February 03
  • Gender:Male

Posted 01 November 2017 - 03:07 PM

It looks like you use ASPRunner.NET but post your questions to ASPRunnerPro forum and get ASPRunnerPro specific answers.
Best regards,
Sergey Kornilov
0

#8 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 01 November 2017 - 05:53 PM

View Postadmin, on 01 November 2017 - 07:07 AM, said:

It looks like you use ASPRunner.NET but post your questions to ASPRunnerPro forum and get ASPRunnerPro specific answers.

My apologies, is there a way I can get this thread moved? Or is it easier for me to close it and reopen it in the ASPRunner.NET forums?

I'm attempting to write the SQL query but its proving to be more difficult than originally thought, specially for entries with multiple upload files.
0

#9 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 02 November 2017 - 05:38 PM

I'm more versed in C++ so my pseudo code is a mixture of it and SQL, now I just need to "translate" it,

int j = 1

int x = count "{" in "UPLOAD_FILE"

for(int i = 1; i <= x; i++)
{
     substring_index(substring_index(UPLOAD_FILE, "{", i), "}", i) as part_j;
     replace([UPLOAD_FILE, substring_index(substring_index(part_j, "_", 1), "/", -1), [UNIQUE_ID])

     j++;
}




This is what my UPLOAD_FILE field looks like:

[{"name":"C:\\Users\\username\\Documents\\Uploads/abcd_udod4v5p.jpg","usrName":"abcd.jpg","size":1013329,"type":"image/jpeg","searchStr":"abcd.jpg,!12345.txt,!:sStrEnd"},{"name":"C:\\Users\\username\\Documents\\Uploads/12345_o6sq520f.txt","usrName":"12345.txt","size":288,"type":"text/plain"}]

0

#10 User is offline   i.NoLim 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 11-September 17

Posted 08 November 2017 - 09:33 PM

I ended up using the following code in the "After record added" event. My only issue is when the upload folder is changed to something like C:\Users\nameofuser\Documents\Uploads. I've attached pictures of my code, error, whats displayed in my DB field, and the settings for said field. As you can see from the third picture, the path in the DB has 2 backslashes; this is most likely causing the issue.

https://www.xlinesof...oaded_files.htm

Posted Image

Posted Image

Posted Image

Posted Image
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users