How cot create and read files in ALLUSERSPROFILE directory

Hi,
I have a program that is to be used both with Windows XP, Vista, 7 and 8. It should create and read a file in ALLUSERSPROFILE, which I have learned to be different directories in XP and the other Windows versions. But after looking all over internet, I can't
find any clear answer how to do this. I thought the following should work, but it doesn't:
testfile = fopen("%ALLUSERSPROFILE%/testfile.dat", "r");
Although the file exist, testfile gets the value of zero. I've also tried other strings instead of "ALLUSERSPROFILE," but no luck. Could anyone tell me how to do this?
Thanks in advance.

I tried the following:
     SHGetKnownFolderPath( &FOLDERID_ProgramData, 0, 0, &userpath); 
Then the program compiled. But it did not work:
     fopen("%userpath%\\Testfolder\\Testfile.ini", "r"); 
did not open the file, although it is there.
Then I read that this function can't be used with Windows XP, so I
switched to the deprecated SHGetFolderPath 
    TCHAR userpath[MAX_PATH];
     SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, userpath);
According to the MSDN pages, one then could use the 
    PathAppend (userpath, TEXT("Testfolder/Testfile.ini"));
I then added Shlwapi.h and compiled and got the following error message 
     main.obj : error LNK2001: unresolved external symbol __imp__PathAppendW@8  
     fatal error LNK1120: 1 unresolved externals
Then I again tried 
   fopen("%userpath%\\Testfolder\\Testfile.ini", "r");
but neither did this work. So now I don’t know what to do.

Similar Messages

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • How to create and use file share in linux

    Hi,
    I just started trying out Azure, I have 2 linux ubuntu instances. I would like to create a File share to use as a type of NAS and mount it on both of the instances.
    How can I go about doing that? Is there a tutorial?
    thanks
    Ricardo

    Hi,
    We can use Azure File services to do this, for more information, please have a look at this article:
    http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx. The Azure File service exposes file shares using the standard SMB 2.1 protocol. Applications running in Azure can now easily share files between
    VMs using standard and familiar file system APIs like ReadFile and WriteFile.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to access and read file

    Hi
    Please can anyone let me know how to display a file in
    textArea of my application??
    the file I basically wanted to get from java..let me know in
    which format I should get from java side and can be able to display
    it!! How to get the file from java???
    I would appreciate if u illustrate the same with an example!!
    Or provide me link!!
    Thanks in advance
    Aruna

    I am using Flex...
    I need to tranfer a file to the specified path!!
    For example to the temp folder on my system or to other
    system!!
    How can I do that!! And How to delete the same using flex!!
    Can I use Http PUT to transfer file and HTTP DELETE to delete
    the file??
    Using urlrequest I am able to read the perticular file in the
    specified location which is @ server, Now I want to save/transfer
    and delete!!
    Provide me any links regarding this...
    Thanks in advance
    Aruna.S.N.

  • How to keep and read files on the client side?

    There's a web page with a certain X3D model, and there are several inputs on the same page. When a user submits the form, the servlet changes the model and returns a page based on the input values. The problem is that the part of this model is a human body (which is pretty tough for downloading). What I'm trying to find out is if there's some way to store that model on the local computer and then access it from the servlet without regetting it from the server. Thanks.

    With JSP you can't run java code on the client. All of it runs on the server.
    To run java on the client, you use an Applet.
    Alternatively you go the pure html/javascript way, and write javascript includes for code.
    Or you use something like AJAX, to submit the form, and receive back only "changes" to the model.
    Not sure if that helps at all.
    Good luck,
    evnafets

  • HOW TO CREATE SEVERAL folder for the generation and READING FILE

    HOW TO CREATE SEVERAL folder for the generation and READING FILE WITH THE COMMAND utl_File.
    please give an example to create 3 folders or directories ...
    I appreciate your attention ...
    Reynel Martinez Salazar

    I hope this link help you.
    [http://www.adp-gmbh.ch/ora/sql/create_directory.html]
    create or replace directory exp_dir as '/tmp';
    grant read, write on directory exp_dir to eygle;
    SQL> create or replace directory UTL_FILE_DIR as '/opt/oracle/utl_file';
    Directory created.
    SQL> declare
      2    fhandle utl_file.file_type;
      3  begin
      4    fhandle := utl_file.fopen('UTL_FILE_DIR', 'example.txt', 'w');
      5    utl_file.put_line(fhandle , 'eygle test write one');
      6    utl_file.put_line(fhandle , 'eygle test write two');
      7    utl_file.fclose(fhandle);
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> !
    [oracle@jumper 9.2.0]$ more /opt/oracle/utl_file/example.txt
    eygle test write one
    eygle test write two
    [oracle@jumper 9.2.0]$
    SQL> declare
      2    fhandle   utl_file.file_type;
      3    fp_buffer varchar2(4000);
      4  begin
      5    fhandle := utl_file.fopen ('UTL_FILE_DIR','example.txt', 'R');
      6 
      7    utl_file.get_line (fhandle , fp_buffer );
      8    dbms_output.put_line(fp_buffer );
      9    utl_file.get_line (fhandle , fp_buffer );
    10    dbms_output.put_line(fp_buffer );
    11    utl_file.fclose(fhandle);
    12  end;
    13  /
    eygle test write one
    eygle test write two
    PL/SQL procedure successfully completed.
    SQL> select * from dba_directories;
    OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH
    SYS                            UTL_FILE_DIR                   /opt/oracle/utl_file
    SYS                            BDUMP_DIR                      /opt/oracle/admin/conner/bdump
    SYS                            EXP_DIR                        /opt/oracle/utl_file
    SQL> drop directory exp_dir;
    Directory dropped
    SQL> select * from dba_directories;
    OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH
    SYS                            UTL_FILE_DIR                   /opt/oracle/utl_file
    SYS                            BDUMP_DIR                      /opt/oracle/admin/conner/bdumpRegards salim.
    Edited by: Salim Chelabi on Apr 4, 2009 4:33 PM

  • HOw to create a Batch file for java application and whats the use of this ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    First of all, you're OT.
    Second, you can find this everywhere in the net.
    If you got a manifest declaring main class (an classpath if needed), just create a file named whatever.bat, within same directory of jar file, containing:
    javaw -jar ./WhateverTheNameOfYourJarIs.jar %*By the way, assuming a Windows OS, you can just double click the jar file (no batch is needed).
    Otherwise use:
    javaw -cp listOfJarsAndDirectoriesSeparedBySemiColon country/company/application/package/className %*Where 'country/company/application/package/' just stands for a package path using '/' as separator instead of '.'
    Don't specify the .class extension.
    Javaw only works on Windows (you asked for batch, I assumed .BAT, no .sh), in Linux please use java.exe (path may be needed, Windows doesn't need it 'cause java's executables are copied to system32 folder in order to be always available, see PATH environment variable if you don't know what I'm talking about) and use ':' as classpath (cp) separator.
    The '%***' tail is there in order to pass all parameters, it only works on Windows, refer to your shell docs for other OSs (something like $* may work).
    This way you have a command you can call to launch your code (instead of opening NetBeans just to see your app working). You could schedule tasks on it or just call it in any command prompt (hope you know what it is 'cause there have been people in this very same forum with no clue about it, if not just hold the 'Windows button' and press 'R', then type 'cmd' and run it).
    Finally add dukes and give 'hem away.
    Bye.

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • How to create a flat files and how i used this

    hi Guys and gals,
    I am david. I want to know how to create a flat files. I don't know about it also. pls explain it and also pls help me to create a flat files. If u have any program for creating pls send me.
    I want to know about retrive the datas from flat files and also insert a record into it.
    pls guide me
    i need this immediately
    david

    void newMethod() throws Exception {
         // Reading from a flat file
         String data;     
         BufferedReader br = new BufferedReader(new FileReader("c:\filename1.txt"));
         while ((data = br.readLine()) != null) {
              System.out.println(data);
         // Writing to a flat file
         BufferedWriter bw = new BufferedWriter(new FileWriter("c:\filename2.txt"));
         bw.write("sample data");
         // After writing the data close the file
         bw.close();
    }

  • How to create and manage the log file

    Hi,
    I want to trace and debug the program process.
    I write the code for creating log file and debugging the process.
    But i am not able get the result.
    please help me how to create and manage the log file.
    Here i post sample program
    package Src;
    import java.io.*;
    import org.apache.log4j.*;
    import java.util.logging.FileHandler;
    public class Mylog
         private static final Logger log = Logger.getLogger("Mylog.class");
         public static void main(String[] args) throws Exception {
         try {
           // Create an appending file handler
            boolean append = true;
            FileHandler handler = new FileHandler("debug.log", append);
            // Add to the desired logger
            Logger logger = Logger.getLogger("com.mycompany");
            System.out.println("after creating log file");     
              catch (IOException e)
                   System.out.println("Sys Err");
            }Please give the your valuable suggesstion... !
    Thanks
    MerlinRoshina

    Just i need to write a single line in log file.

  • How to create and sign CAB files info on Supplement Option

    To all Supplement Option subscribers:
    At the supplement option for iDevelopment Accelerators, I uploaded a zip with detailed info on how to create and sign CAB files (necessary when you are running your application on the Native IE Java Virtual Machine).
    Not all functionality provided to you through JInitiator will work (e.g. WebUtil doesn't) but the way how to make and sign a CAB file will become more easy.
    Cheers,
    Marc Vahsen
    Headstart Team

    This defeats the purpose of trying to centralize SAP-related web resources on the SAP server. Typically IIS/Apache or other non-SAP servers are under the control of IT and not the SAP BASIS group.
    We simply would like to have a centralized location to store static web files so that they are not overwritten during Portal support pack applications.

  • How to add Mac27" to existing home network? and read files on other PC computers (Window7)

    How to add Mac27" to existing home network? and read files on other PC computers (Window7).
    type of connection:
    All computer (PC & Mac) connect to router (ethernet or wireless), then connect to internet.
    condition:
    internet works fine on all computer (PC & Mac).
    existing 4 PC communicate well (share files & printers),
    my problem:
    can NOT add Mac into existing home network.
    I tried SYSTEM PREFERENCES, then NETWORK, then ......... several times
    could not make it work.
    pleas help.

    Ah, it looks like I should have read your title more carefully. Are the  files on the PCs that you want to share with your iMac in a shared folder?
    If not, follow the steps on this page to set up shares from Windows 7.
    If that is already set up, connect to the share from the iMac using this article.

  • How to create and export a sharepoint list connection file to excel connection file library from power pivot?

    Hi All,
    I'm new to SharePoint and Power BI.
    I've to use  share point 2013 lists to create power view reports. For that, I need to create Power Pivot in Excel 2013.
    I'm fine with the above. We normally take a data feed of a list and create connection to that. We need to create a connection file (.odc) and export it into a excel file connection library of Share point. The connection to be made to share point list. The
    power pivot will be having multiple related lists.
    How can I create a connection file which is referring to share point list
    Please suggest.
    Regards,
    Julie

    Hi All,
    Finally, I could find the answer for this question after a long search.
    First of all, open a new excel file in server.
    Data-->From other connection-->From data connection wizard-->data feed-->Location of the data feed-->
    http://sharepointsite/sitename/_vti_bin/ListData.svc
    -->next-->select the lists which you need-->next-->only create connection-->properties--->export connection file
    -->ok
    The connection file has been created and .odc file exported to the specified location.
    Open power pivot and check the connection in existing connections.
    Exported file has to be uploaded in Excel file connection library of share point 2013. So that you can refer the same in this excel file when you upload it into share point.
    Regards,
    Julie

  • How to create and save a file in flex web application ?

    Hi,
          I want to create and save a file form flex web application. Is it possible ?
    I have done some googling and found that its only possible through file referece, which needs some serverside implementation be called.
    Is it not possible with file reference to create and save file directly ?
    Can any one suggest how to over come this.
    Thanks in advance.

    Alex,
    code written with the Flex Builder 3 libraries will certainly run in Flash Player 10. However, what you need is not so much the capabilities of FP10 but the library functionalities of the Flex 4 package. And I think that Flex 4 code will only run in FP10 and not 9 (but haven't tested this as at work we have not yet been permitted to upgrade, so there is not a lot of point going for Flex 4!).
    Richard

  • How to get and read a file from META-INF directory

    how to get and read a file from META-INF directory in a EJB project

    Use this.getClass().getResourceAsStream("/META-INF/filename");This should work. Probably, you would need to set the Manifest Class-Path attribute.

Maybe you are looking for

  • Macbook 13 boots to blank screen but still works on external. What's wrong?

    My Late 2008 Macbook Aluminum Unibody screen suddenly stopped working for me today. I booted it up, heard a chime, but the screen is a dark blue tint. It doesn't show anything on the screen at all. I can change the brightness and darkness of the scre

  • How to convert a string value to date

    Dear All, I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date. but when i try to convert the variable to date value, I am getting the error as below. Please h

  • Confusion about posting, due, doc date

    Hello there, I am very confused by dates used in SBO documents, could anyone please explain for me? For example, We receive an invoice from supplier, which is dated on 1st Oct. And then we input it into SAP on 5th Oct. Based on the payment term, say

  • Ipod wont work in wall outlet?

    I have a Ipod 4 gen and it has stopped working plugged into the wall but works in the computer. I have tried the cords to see if they work and they work with others. What do I do?

  • Writing to files within EJBs

    I know the EJB spec says I'm not allowed to access any files from within an EJB. I recently discovered a developer on our team is using a FileWriter to do some custom outputting. I'm fairly sure that he's not allowed to do what he's doing, but to be