function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AAlex11AAlex11 

Insert file txt in Visualforce page

Hi,
I'm creating a VF Page with a two columns table.
In the two columns I have to insert for each row a .txt file loaded from static resource.
That's my problem:
When I loaded the txt file in Visulaforce page with this line of code:
​<tr><b>{!$Resource.Cond1}</b></tr>

where Cond1  is the name of the txt file I loaded in static resources

My output in the page is
/resource/1469117262000/Cond1
instead of the actual content of txt Cond1 file.
Where am I wrong?
There's a special visualforce tag to use?
Please help me to solve this issue.


 
Best Answer chosen by AAlex11
Ankit SehgalAnkit Sehgal
The StaticResource object is readable via a normal SOQL query.
Add a property to your controller that queries the static resource and returns its body assuming the body is text:
public String textFromSomeUniqueName {
    get {
        StaticResource sr = [
                select Body
                from StaticResource
                where Name = 'SomeUniqueName'
                ];
        return sr.Body.toString();
    }
}

The page can then output the text using:
 
{!textFromSomeUniqueName}