Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetShortPathName

Posted on 2007-11-14
8
Medium Priority
?
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Loops Section Overview

598 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