Solved

GetShortPathName

Posted on 2007-11-14
8
756 Views
Last Modified: 2013-12-17
I would like to make "f.FileName" and "f.SelectedPath"  below the short paths, but I'm not sure what I need to declare...I keep getting errors beyond the syntax of my GetShortPathName(xx,xxx,xx)
so I figured I'd just let someone get the points...


Here's the current code that I want to change to shortpath:

        private void buttonBrowseFiles_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog f = new OpenFileDialog())
            {
                f.FileName = this.textBoxBackupSelection.Text;
                f.Multiselect = false;

                if (f.ShowDialog() == DialogResult.OK)
                {
                    this.textBoxBackupSelection.Text = f.FileName;
                }
            }
        }

        private void buttonBrowseFolders_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog f = new FolderBrowserDialog())
            {
                f.ShowNewFolderButton = false;
                f.RootFolder = Environment.SpecialFolder.MyComputer;

                f.SelectedPath = this.textBoxBackupSelection.Text;

                if (f.ShowDialog() == DialogResult.OK)
                {
                    this.textBoxBackupSelection.Text = f.SelectedPath;
                }
            }
        }
0
Comment
Question by:lvnv
  • 5
  • 2
8 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20282592
What do you mean by short path?

0
 

Author Comment

by:lvnv
ID: 20282911
GetShortPathName Function  ... it's a M$ thing...
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 20282934
Not that we don't like points....  but there is a nice web site out there called pinvoke.net that has (almost all) of the Win32 API declarations already written for you!

http://www.pinvoke.net/default.aspx/kernel32/GetShortPathName.html

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lvnv
ID: 20284184
graye - REALLY COOL SITE ... I will definitely use that more in the future!

it should be called more than anyone ever needed to know about p/invokes...

but where do I put this?

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath,
        [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath,
        int cchBuffer);



0
 
LVL 41

Expert Comment

by:graye
ID: 20285178
just put it inside a class somewhere, and then call it like any other part of the language/framework, such as

StringBuilder sb = new Stringbuilder(12);
GetShortPathName("c:\\somelongfilename.text", sb);
0
 

Author Comment

by:lvnv
ID: 20285293
I get this error:
"the type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)

<aside: the grammar seems weird in the error, but that's what it says>


I sure thought this would be easier than it has turned out...

GRRR....
0
 

Author Comment

by:lvnv
ID: 20285609
using System.Runtime.InteropServices;

needs to be at the top...



I sure with that there was a definitive guide to this.  My style of learning just doesn't seem to agree with the M$ documentation...


0
 

Author Comment

by:lvnv
ID: 20285925
that's really a good site!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 32
asp web application 3 43
Convert Silverlight ERP To Angularjs,HTML5 3 62
Amazon S3 .Net error 5 43
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question