# File name contains spaces and underlines after download

**URL:** <https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 16, 2024, 6:21am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270 "2024-07-16T06:21:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olli\_Burr](https://avatars.discourse-cdn.com/v4/letter/o/9de0a6/32.png) [@Olli\_Burr](https://forum.inductiveautomation.com/u/Olli_Burr)\
**Post date:** [July 16, 2024, 6:21am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/1 "2024-07-16T06:21:48Z")

</div>

Hi there,

I currently have the problem that as soon as I want to download a file from the SQL Server, the file is displayed with spaces and the format is underlined (see pic below).

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0e5066721c38be45b9fbeba1b2de79fab842de90.png)

The file name is made up of the seperately strored columns [Filename] and [Filetype] .

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/67ab22b9edc0f7287beb4bcd1cae77cbb429f6f6.png)

To download the file I use the following code:

```python
for i in range(fileReceived.getRowCount()):
		fileName = fileReceived[i]["Filename"]
		system.perspective.print(fileName)
		fileType = fileReceived[i]["FileType"]
		system.perspective.print(fileType)
		uploadedFile = fileReceived[i]["UploadedFile"]
		#system.perspective.print(uploadedFile)
		fileString = str(fileName + "." + fileType)
		system.perspective.print(fileString)		    
			    

	       if uploadedFile:
		      system.perspective.download(fileString, uploadedFile)
				
           else:	
	          system.perspective.openPopup()

```

This is what DevTools is dispaying in regard of the system.perspective.print() functions:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/f/7fa141836a19fdffef71dc7d6e63495d1e80c2ba.png)

Any idea on how to solve this problem?

Any kind of help is much appreciated!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 16, 2024, 12:21pm UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/2 "2024-07-16T12:21:17Z")

</div>

It looks like maybe your database entries aren't sanitized and contain whitespace and/or newlines?

Try:

```python
fileName = fileReceived[i]["Filename"].strip()
fileType = fileReceived[i]["FileType"].strip()

```

---

<div class="post-metadata">

**Author:** ![Olli\_Burr](https://avatars.discourse-cdn.com/v4/letter/o/9de0a6/32.png) [@Olli\_Burr](https://forum.inductiveautomation.com/u/Olli_Burr)\
**Post date:** [July 17, 2024, 8:17am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/3 "2024-07-17T08:17:57Z")

</div>

Kevin, you're a legend! You made my day!

It worked using `.strip()`

Thank you tons!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 17, 2024, 9:51am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/4 "2024-07-17T09:51:36Z")

</div>

There's something else to take from Kevin's answer: Maybe you should look at how things are inserted into your db, and clean things up before hand.

That doesn't mean you shouldn't also make sure you're getting proper data out and sanitize it, but having clean data in your db is never a bad thing.

---

<div class="post-metadata">

**Author:** ![Olli\_Burr](https://avatars.discourse-cdn.com/v4/letter/o/9de0a6/32.png) [@Olli\_Burr](https://forum.inductiveautomation.com/u/Olli_Burr)\
**Post date:** [July 17, 2024, 10:02am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/5 "2024-07-17T10:02:21Z")

</div>

Good point - wasn't really paying attention to what I'm actually writing into the SQL-DB...

I've just checked and the number of blanks correlate to the selected Datatype (see pic below).  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/a/caa426775f5335df433c97370bc1fa8745e687a9.png)

For instance - "Test1" equals 5 characters though 50 in total are reserved due to the datatype [nvarchaer(50)]. Hence when retrieved from the SQL-DB IGNITION is taking the whole bunch of 50 Characters, including the blanks...

Not sure if what I'm doing is bad practice so I'm open for opinions...

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 17, 2024, 10:08am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/6 "2024-07-17T10:08:19Z")

</div>

If you need variable length strings, use `nvarchar` instead.  
You can still have a maximum length, using `nvarchar(50)` for example, but the stored value will not be padded with whitespaces.

A few notes about what I'm seeing:

- "Type" is a string. This is not ideal. I'd suggest either a int that represents an enumeration in your code, or a foreign key to a separate table that holds the actual types descriptions.
- "FileVersion" should probably be an numeric value as well
- "Date" is a `datetime`, which is not so bad, but it seems to me you're using sqlserver. If that's the case, use [`datetime2`](https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetime2-transact-sql?view=sql-server-ver16) instead.

Disclaimer: I am in no way a db specialist, I'm only talking about a few things I picked up over my small experience with them.  
I know adding constraints and reference tables and such may seem like it will add a lot of work, but in the long run these things protect your data integrity and will save you a lot of headache down the road. A properly setup database is a VERY powerful tool to have in your application.

I'll also suggest throwing an eyeball at database normalization:

> **[Database normalization](https://en.wikipedia.org/wiki/Database_normalization)**
>
> Database normalization is the process of structuring a relational database in accordance with a series of so-called normal forms in order to reduce data redundancy and improve data integrity. It was first proposed by British computer scientist Edgar F. Codd as part of his relational model.
> Normalization entails organizing the columns (attributes) and tables (relations) of a database to ensure that their dependencies are properly enforced by database integrity constraints. It is accomplished b...

I haven't read this wikipedia article, but I'm guessing it will be insightful.  
You can also search google to find better articles.

---

<div class="post-metadata">

**Author:** ![Olli\_Burr](https://avatars.discourse-cdn.com/v4/letter/o/9de0a6/32.png) [@Olli\_Burr](https://forum.inductiveautomation.com/u/Olli_Burr)\
**Post date:** [July 17, 2024, 10:44am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/7 "2024-07-17T10:44:33Z")

</div>

Thank you, Pascal, for the valuable information - it is greatly appreciated!

I will make the necessary changes to my table regarding the "nvarchar(50)" field type. It makes much more sense.

I just wanted to make a few additional remarks. The [ID] field in the "Files" table is already functioning as a foreign key. The "Type" field refers to internal document types that are uploaded by users of my application, such as "Drawing", "STEP File", and similar types. Therefore, I am afraid that I will have to stick with using a string for this field. The same goes for the "FileVersion" field, as the CAD department is using characters instead of numbers.

Still - Thanks for the support!!!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 17, 2024, 12:04pm UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/8 "2024-07-17T12:04:32Z")

</div>

The ID column is a primary key, not a foreign key.  
A foreign key references the primary key of another table. It's what makes a relational database relational. While you can have only one primary key (which could use more than one column, we'd say it's composite), you can have as many foreign keys as you like.

---

<div class="post-metadata">

**Author:** ![Olli\_Burr](https://avatars.discourse-cdn.com/v4/letter/o/9de0a6/32.png) [@Olli\_Burr](https://forum.inductiveautomation.com/u/Olli_Burr)\
**Post date:** [July 18, 2024, 7:51am UTC](https://forum.inductiveautomation.com/t/file-name-contains-spaces-and-underlines-after-download/93270/9 "2024-07-18T07:51:25Z")

</div>

Yes, it is a primary key, but this primary key is already being used as a foreign key in another table.

I simply wanted to point out that we're already - well, at least trying - to adhere to the "normalization" standard 🙂
