From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Open File Explorer from button?

I want to open up the file explorer when I click on a button that I created called "Save File". I want the file explorer to default to a directory of my choice. I'm not sure if there is a lab windows specific function that I can add into my SaveFile callback function. Any help appreciated. Thanks.

0 Kudos
Message 1 of 10
(7,538 Views)

The FileSelectPopup in the User Interface library does permit you to specify the default directory.

 

--Ian

Message 2 of 10
(7,533 Views)

Ok, thanks for the reply. I used the FileSelectPopUp and it worked correctly(took me to the directory I wanted) except I couldn't save the file. Here is my callback function. Could anyone tell me what I'm doing wrong. Thanks!

 

int CVICALLBACK SaveTblkFile(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)

{

char pathName[MAX_PATHNAME_LEN];

string dir_append = "\\TblkFiles"; 

char *path = NULL;

path = _getcwd(path,200);

path = strcat(path, dir_append.c_str());

switch (event)

{

case EVENT_COMMIT:

FileSelectPopup(path,"*.txt","*.txt","Save Tblk File",VAL_SAVE_BUTTON,0,0,1,1,pathName);

break;

}

return 0;

}

0 Kudos
Message 3 of 10
(7,528 Views)

Well, you are simply NOT saving the file! Smiley Surprised

 

FileSelectPopup opens up a windows explorer window and VAL_SAVE_BUTTON instructs the system to label the button as "Save" (and perform some check for already existing file, too), but it actually does not do anything else: saving the file is your responsibility and you can do it with ordinary file I/O commands or just a CopyFile if you already have data on disk based file name and path retrieved in pathName variable



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 10
(7,516 Views)
doh! Thanks for the tip. Should have figured that one out 🙂
0 Kudos
Message 5 of 10
(7,471 Views)

what to do if i want to dsiplay the complete path of the selected file in a dialog box on my .uir kindly guide

0 Kudos
Message 6 of 10
(6,171 Views)

It depends on what do you intend to do with it. "Dialog box" is a rather generic term: you can use

  • a simple string control filled with SetCtrlVal, or
  • Some popup like MessagePopup or ConfirmPopup, or
  • some more complex user interface

What is you goal?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 10
(6,166 Views)

thanks alot for the answer although it was not a good question by me , well i have new issue related to it .

i have used a dialog box to display file name on which i want to save data, and a command button to use FileSelectPopUp .

well i have set a default path vale to the dialogbox specifing certian file name and  if i dont specify a file it  gets dafault value as complete path .

now i have an issue.

i want that if i select a specific file or specific COM port now then when i reopen the application next day or next time then the default path and default COM are the same specified by me last time so that i dont have to select everytime, i have used SetCtrlAttribute to chage the default value of  Dialog Box or Menu Ring but still i am unsucessful please guide me, i will be really thankful to you.

 

0 Kudos
Message 8 of 10
(6,063 Views)

You cannot modify existing default value for controls in a UIR so that they survive a program shutdown.

What you can do is to save your desired default values in a file, reload at program start and apply them where needed.

As an alternative, you may want to consider SavePanelState and RecallPanelState commands. I personally go the first way by I point you to those commands so that you can evaluate and use them if you consider they are better for your actual needs.

 

 

 

BTW, I urge you to open a new thread when additional questions, like in this case, are not related to the original one. This will help other users to better locate discussion that may be of help to them



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 10
(6,061 Views)

thanks alot Sir i was given this advise by friend expert in .Net as well and i prefered asking you and now i will act on your advise thanks alot Sir.

0 Kudos
Message 10 of 10
(6,057 Views)