|
There are no controls "purely for C# applications". Controls are for a specific purpose and are usually exposed through COM. So, you can use just about any control you want in your app. It's the applications requirements that determine the control you're going to use, not the language you use it in.
|
|
|
|
|
|
Has someone written this?
I note that it exists in System.IO.Packaging, supported by Vista only, as PackUriHelper.GetRelativeUri.
But I'm surprised it doesn't exist in System.IO.Path. Anyone have a (working!) implementation?
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
Hi Marc,
I think you have to expand on the specifications.
Anyway, isn't it just about locating one (the last?) backslash?
IMO the last one is what Path.GetFileName() does.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: I think you have to expand on the specifications.
Taking an example from GetRelativeUri:
If my application is executing out of /mydoc/markup/ (which I can provide, of course) and I open the file /mydoc/picture.jpg, I want the relative path to be ../picture.jpg.
If I open a file in /mydoc/foobar/picture.jpg, I want the relative path to be ../foobar/picture.jpg.
Maybe it really is as easy as finding the common path and figuring out how many levels to go up and then branch.
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
OK,
I had a look inside GetRelativeUri and it expanded to
return new Uri(PathDifference(this.AbsolutePath, uri.AbsolutePath, !this.IsUncOrDosPath) + uri.GetParts(UriComponents.Fragment | UriComponents.Query, UriFormat.UriEscaped), UriKind.Relative);
So that is probably not the solution.
I think along these lines (not tested, and not throwing when target shorter than ref):
public static string MakeRelativePath(string refPath, string targetPath) {
string[] parts1=Path.GetFullPath(refPath).Split('\\');
string[] parts2=Path.GetFullPath(targetPath).Split('\\');
int i=0;
for (; i<parts1.Length && i<parts2.Length; i++) {
if (string.Compare(parts1[i], parts2[i])!=0) break;
}
string result="";
for (int j=i; j<parts1.Length; j++) result+="..\\";
result+=string.Join('\\', i, parts2.Length-i);
return result;
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You can do this with some P/Invoke code:
public const int MAX_PATH = 260;
public const uint FILE_ATTRIBUTE_DIRECTORY = 0x10;
internal const string SHLWAPI = "shlwapi.dll";
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathRelativePathTo([MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder pszPath, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszFrom, uint dwAttrFrom, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszTo, uint dwAttrTo);
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathIsDirectoryEmpty([MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszPath);
public static string PathRelativePathTo(string from, string to)
{
string result = String.Empty;
StringBuilder path = new StringBuilder(MAX_PATH);
uint fromAttributes = IsDirectory(from) ? FILE_ATTRIBUTE_DIRECTORY : 0;
uint toAttributes = IsDirectory(to) ? FILE_ATTRIBUTE_DIRECTORY : 0;
if (PathRelativePathTo(path, from, fromAttributes, to, toAttributes))
{
result = path.ToString();
}
return result;
}
public static bool IsDirectory(string path)
{
return PathIsDirectory(path);
}
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
modified on Thursday, August 13, 2009 7:49 PM
|
|
|
|
|
Thanks Scott. I'll add it to my toolbox.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You're welcome.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Marc, see my reply to Luc here[^] which gives you the P/Invoke code necessary to call the PathRelativePathTo function from shlwapi.dll. This should give you what you are after.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi ,
I have 2 buttons on the form, SAVE and PRINT .. I want the user to click on the SAVE button first to save the current record and then print it. Now.. my question is.... if the user clicks first on the PRINT button before clicking on the SAVE button.....I want to alert the user using MessageBox etc.... upon click..that the record needs to be save first(by clicking on the save button) etc... how can i achive this....
(I have done the enable and disable operations by it was not accepted by the client .... ie on from_load ,,, disable print and enable save ....and on save_click enable print)
thanks,
|
|
|
|
|
I think you must implement something like isDirty variable.
That means, if the user change something, you must set isDirty=true.
if(isDirty)
{
MessageBox.Show("Please save first");
}
else
{
}
|
|
|
|
|
OKay thanks, it did the trick !!
|
|
|
|
|
I have device running Windows CE 5.0.
I am developing an application for it in C# using a SQL server mobile database.
In order to install the database on the device,I first have to add SQLserverCE.dll.But I don't know why the folder or dll is not available. I tried to install Microsoft SQL Server Mobile Developer Tools.but still nothing.
I also reinstalled SQl Server 2005...
|
|
|
|
|
Hi
I m very fresh guy for developement field. Actually I need to edit a opendocument spreadsheet.ods file. In c# I could not add a namespace for that, like
using Excel = Microsoft.Office.Interop.Excel
for this what are the settings to be made, i m having visual studio 2005.
Please let me know about it.
Thanks
Sath.
|
|
|
|
|
Have you added a reference to that assembly?
|
|
|
|
|
Hi
In my system Excel has been uninstalled, I have only openoffice. I can't find any Excel related dll to add reference. Could you please tell the corresponding dll for Openoffice.
Thanks
sath.
|
|
|
|
|
|
This won't allow the OP to open opendocument format files.
ODS formats are xml files and so no need to add namespaces for them nor reference any dlls - but will have to use the XML stuff in C#.
Here's a link that may help: http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c16311/[^]
Don't know how good it is - got by googling 'opendocument c# .ods'.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hey!
I´m looking for a code that i can see the monitor from an other Pc on my network(how teamviewer). I have a Server and Client i can write something to him and i can send him files and now i will see the monitor when there is a change.
|
|
|
|
|
|
okay thank you i will try it!
|
|
|
|
|
I have downloaded the Prog/Code!
And how can i start it? I have opened the sln file in C# and then?
Can i copy the Code into a server and client?
|
|
|
|
|
Hi All,
I am creating a windows app, with MVP architecture.
In presenter, I am adding nodes to the treenode, so in doing so, I am initializing
<pre>TreeNode MainNode = new TreeNode();
MainNode.Name = strProjectFolderPath;
MainNode.Text = strProjectFolderPath;
_view.AddTreeNodes(MainNode);
</pre>
I see the error, when I put a watch on MainNode,
FullPath = 'MainNode.FullPath' threw an exception of type 'System.InvalidOperationException'
Actually I am trying to add items to this main node, so that I get the treeview from the folder.
Please help me in solving this
Thanks
Ramm
|
|
|
|
|
Hi,
You probably need to act according to this article[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|