Load a txt file using UNC

Ok thanks for helping me with the text file question I had. Now I have another little problem. I have this code here
//...
BOOL CWarningMessageDlg::OnInitDialog()
{
      CDialog::OnInitDialog();
//...
      CFile file;
    file.Open("C:\\Warning.txt",CFile::modeRead);
    int n = file.GetLength();
    char * pzsBuf = new char[n];
    file.Read(pzsBuf,n);
    m_Message = pzsBuf;
    UpdateData(FALSE);
//...


My questions is how can I loaded a text file that's on a network path using UNC? Instead of C:\Warning.txt I want to use \\server\folder\Warning.txt
LVL 2
fredmastroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
Where you have:

C:\\Warning.txt

replace it with:

\\\\server\\folder\\Warning.txt

if the network path is valid, then it will work.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

No Prob

file.Open("\\\\server\\folder\\Warning.txt",CFile::modeRead);

will solve Ur prob.

Try it out.
VinExpert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhanceCommented:
VinExpert,

Thanks for stealing my answer!!
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

gvgCommented:
Hi,

If the folder isn't shared you can use the drive letter C$ for example.

file.Open( "\\\\MyServer\\C$\\Folder\\Warning.txt", CFile::modeRead );

Note: If you have a shared server drive that you have mapped for example as h: on you computer you can get the UNC by using the function WNetGetUniversalName.  It would translate H:\Warning.txt to \\MyServer\C$\Folder\Warning.txt

Gunnar Valur.
0
Vinayak KumbarSr Program ManagerCommented:
Hi jhance,

U R welcome, better luck next time!!!(:-))

VinExpert
0
jhanceCommented:
Well at least it shows you can read.  

If the best way you can find to get points is to steal other people's answers, then I guess I should be honored that you think mine are good enough to rip off....
0
gvgCommented:
Just one question jhance

Why didn't you put it as a answer instead of a comment since it is the answer?
0
jhanceCommented:
Just a coutesy to the asker.  If it's locked with an answer, it no longer show up in the available questions.  The staff at EE has been encouraging experts to post comments and let the owner of the question choose the right one as an anwser.  In fact, they are considering removing the ANSWER choice altogether.  I've been trying to use this method recently but experts like the one above are one of the reasons why this courtesy won't work.
0
gvgCommented:
I agree with you.  Answers should be removed. I hope fredmastro gives you the points since you were first.
 
0
jhanceCommented:
Thanks fredmastro, you're a real pal!  

You gave the credit where credit was NOT due!
0
Vinayak KumbarSr Program ManagerCommented:
Hi jhance,

I never meant to heart U.(sorry if it is the case.) But I posted it as an answer without seeing Ur comment.(We did it almost the same time.) So no question of getting the points by stealing others answers. I too put the answers as comments if I am not 100% sure of the case. That I think almost all experts do. If U think u should get points, then no prob, fredmastro can ask EE to settle it. So peace... Ok(thanks and sorry if my comment has hearted U).

Regards,

VinExpert
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Replace all 'heart' with 'hurt'.

:-)

VinExpert
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.