How can I read a local file in FiddlerScript?

2 Answers 532 Views
Fiddler Classic
Alex
Top achievements
Rank 1
Iron
Iron
Alex asked on 24 Jan 2023, 10:19 AM
I searched the web and found the .NET 'File.Open' instruction, but I have not been able to successfully use it in my script.

I am looking for something like this...

var content = File.Open('path/filename.txt');

This code is just an example, it does not work.

Thank you!

Alex
Alex
Top achievements
Rank 1
Iron
Iron
commented on 24 Jan 2023, 11:56 AM | edited

I just found another message on the same subject. I posted it myself a year ago, and I am sorry to say that I completely forgot about it ;-). Anyhow, Nick had this suggestion for me: "it is possible to write to a file (see this thread), so you should do the same in the other direction". I read the thread, but I just do not see how I could reverse the direction and be able to read a file that way. If you could please guide me with some code example, that would be great!

2 Answers, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 24 Jan 2023, 12:03 PM

Hello Alex,

 

You can use System.IO.File class and its methods. Note that you must have read rights for the folder you are accessing.

Example

using System.IO; 

var folderPath = "./test.txt";
var streamReader = System.IO.File.OpenText(folderPath);
var s;

while ((s = streamReader.ReadLine()) != null)
{
    MessageBox.Show(s);
}

Regards,
Nick Iliev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Alex
Top achievements
Rank 1
Iron
Iron
answered on 24 Jan 2023, 01:09 PM

Wonderful, thank you!

While searching the web for details on your code, I found an instruction that reads the entire file content at a time:

var content = File.ReadAllText('path/filename.txt');

It works for me. I found it on this Stackoverflow thread.

Alex

Tags
Fiddler Classic
Asked by
Alex
Top achievements
Rank 1
Iron
Iron
Answers by
Nick Iliev
Telerik team
Alex
Top achievements
Rank 1
Iron
Iron
Share this question
or