473,769 Members | 4,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read/Write to text file in chrome.. Is there a way?

7 New Member
I am writing an extension for Firefox 1.5.

I would like to know if there is a way to write and read data to and from a file which is in the location of the extension (or somewhere in the user's harddisk, where I can store and retrieve some data). I tried to use a write function which I found in one of these threads and tried to give it "chrome://followmylink/files/" as the path.

Expand|Select|Wrap|Line Numbers
  1. function fileWriter (filename,content) {
  2.   try {
  3.     var filePath = "chrome://myextension/files/"+filename;
  4.     netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
  5.     var file =Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  6.     file.initWithPath(filePath);
  7.     if (!file.exists())
  8.       file.create(0x00, 0644);
  9.  
  10.     var outputStream =Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); 
  11.     outputStream.init(file, 0x20 | 0x04, 00004, null);
  12.     outputStream.write(content, content.length);
  13.     outputStream.flush();
  14.     outputStream.close();
  15.     return true;
  16.   }
  17.   catch (e) {
  18.     alert(e);
  19.     return false;
  20.   }  
  21. }
thank you very much
Apr 27 '06 #1
3 8836
broli85
7 New Member
I am writing an extension for Firefox 1.5.

I would like to know if there is a way to write and read data to and from a file which is in the location of the extension (or somewhere in the user's harddisk, where I can store and retrieve some data). I tried to use a write function which I found in one of these threads and tried to give it "chrome://followmylink/files/" as the path.

Expand|Select|Wrap|Line Numbers
  1. function fileWriter (filename,content) {
  2. try {
  3. var filePath = "chrome://myextension/files/"+filename;
  4. netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
  5. var file =Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile );
  6. file.initWithPath(filePath);
  7. if (!file.exists())
  8. file.create(0x00, 0644);
  9.  
  10. var outputStream =Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutpu tStream); 
  11. outputStream.init(file, 0x20 | 0x04, 00004, null);
  12. outputStream.write(content, content.length);
  13. outputStream.flush();
  14. outputStream.close();
  15. return true;
  16. }
  17. catch (e) {
  18. alert(e);
  19. return false;
  20. }
  21.  
thank you very much
Apr 27 '06 #2
broli85
7 New Member
I am trying to write a function that would write to text file, and each time it tis called, it would write in the next line. This is what I currently have however, this is just overwriting what there is already:

Expand|Select|Wrap|Line Numbers
  1. function fileWriter (filename,content) {
  2.   try {
  3.     var filePath = folderpath+filename;
  4.     netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
  5.     var file =Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  6.     file.initWithPath(filePath);
  7.     if (!file.exists())
  8.       file.create(0x00, 0644);
  9.  
  10.     var outputStream =Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); 
  11.     //outputStream.init(file, 0x20 | 0x04, 00004, null);
  12.     outputStream.init(file, 0x02 | 0x10, 00004, null);
  13.     outputStream.write(content, content.length);
  14.     outputStream.flush();
  15.     outputStream.close();
  16.     return true;
  17.   }
  18.   catch (e) {
  19.     alert(e);
  20.     return false;
  21.   }  
  22. }
  23.  
Please Help!

Thank you
Apr 28 '06 #3
broli85
7 New Member
I am trying to find a way to save the user settings of a Firefox Extension. I need two types of storage. One that would store a small number of settings and the other that would store a large number of data that is accumulated by the user while he/she is browsing.

I was thinking of storing the info in a textfile located in the chrome directory of the extension but doesnt seem to work using a normal writing procedure (see my previous post).

Any Ideas??

Thanks very very much for any help
Apr 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
31014
by: Patrik Malmström | last post by:
How do I read, write a file binary? I want to open, say, file.exe read it in to the program, then write it out to file2.exe. Like file copy, anyone have a code sample?
1
10125
by: WebSim via .NET 247 | last post by:
Hi, I want to read a text file, and then write it into dataset. Is it possible? or Is there any solution that read text file into DB? ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>x/Vs9+Nw2U6Px6tC6dj55w==</Id>
4
1988
by: who be dat? | last post by:
I feel stupid for asking this but I can't figure this out. I've got some text files I want my website to read. The text files are located in a subdirectory of my application. Physically, the files are located on drive C: in directory starting with InetPub/myapplication/directrory/files . Thing is,when the website is running, the application path is c:\windows\system32. I can manipulate the path to get this to work for now. Thing is,...
0
5682
by: Ahmed A. | last post by:
This will be very helpfull for many! Using RichTextBox Read/Write Unicode File http://www.microsoft.com/indonesia/msdn/wnf_RichTextBox.as p Private Function ReadFile(ByVal myfile As String) As String Dim myFileStream As Stream = File.Open(myfile, FileMode.Open)
3
2279
by: ad | last post by:
I have a text file in the directory of my web application. How can I read this text file into a string vaiable?
5
2265
by: jannordgreen | last post by:
I use windows 2000 and Visual Studio 2003. I have a vbnet web application on our intranet that needs to read a text file that sits on a different server. The general user does not have access to the server where the text file is sitting. Is there any way my web application can be given access rights to read the text file? At the moment we copy the text file to the web server where it can be read by the web application. We have it...
4
2452
by: Alessandro | last post by:
Hi everybody, I tried to find some information about my subject with google, but I didn't find anything. I need to read a text file, process the entire content, then kill. In the meantime I have to be sure that no one could write on it. So I opened with read write lock, but when i closed it, before deleting, someone wrote something, and I lost the information because immediately after I killed it.
6
248996
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using System; using System.IO; using System.Diagnostics;
3
1589
by: Raymond Chiu | last post by:
Dear all, Now I have the simple task to read text file line by line into database (SQL Server 2000). If the text file is divided into different fields according to the number of characters, What is the best method to read into database. In Oracle, I know it has sql loader. As to SQL Server, What should be? Do I need to write the program to read each characters and line by line? Thanks,
2
3950
by: Scottie Boy | last post by:
Ok, I'm brand new to IIS and asp. (My experience is with apache on Solaris but we have gotten rid of that system.) I need to readin a text file with asp that is on the C: drive of another Windows server that is not running IIS. I created a share on folder containing the text file on the second server and made it available to the Everyone Group. The asp program, which works when the file is local, doesn't work when I modify the...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.