Solved

how to recover all uri but the filename ?

Posted on 2010-11-22
6
415 Views
Last Modified: 2012-05-10
hello experts,

i have an Uri object that i'd like to use in order to create a new file.
i'd like to change the last info in the Uri in order to keep the path.

is there an easy way to achieve this ?

example:
Uri test = new Uri(@"c:\path\to\the\file.txt");   // 1. i have an Uri.
ChangeFile(test, "otherFile.txt")                      // 2. change the file for the same uri
Uri test -> c:\path\to\the\otherFile.txt            // 3. now my uri is changed.  

thank you in advance.

 

0
Comment
Question by:toshi_
  • 4
6 Comments
 
LVL 4

Accepted Solution

by:
Andre412 earned 125 total points
ID: 34189626
hi

use a combination of the following as you eed

 
       Dim folder As String = IO.Path.GetDirectoryName("old path")
        Dim filename As String = IO.Path.GetFileName("old path")
        Dim NewFilename As String = "predicate" & filename
        IO.Path.Combine(folder, "new filename")

Open in new window

0
 
LVL 4

Expert Comment

by:Andre412
ID: 34189649
oops sorry made a small error

Dim folder As String = IO.Path.GetDirectoryName("old path")
Dim filename As String = IO.Path.GetFileName("old path")
Dim NewFilename As String = "predicate" & filename
Dim newlocation As String = IO.Path.Combine(folder, "new filename")

Open in new window

0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 125 total points
ID: 34189679
something like this:

int position = uri.LocalPath.LastIndexOf('\\');
String newPath = uri.LocalPath.Right(position) + 'otherFile.txt';
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:Andre412
ID: 34189765
or the c# version seeing as we are in the c# section

Its better to use the .net path library than to guess the structure will adhere to a predicted format and use string functions

string folder = System.IO.Path.GetDirectoryName("old path");
string filename = System.IO.Path.GetFileName("old path");
string NewFilename = "predicate" + filename;
string newlocation = System.IO.Path.Combine(folder, "new filename");

happy coding :-)
0
 
LVL 4

Expert Comment

by:Andre412
ID: 34189814
I'm making mistakes all over the place today

string folder = System.IO.Path.GetDirectoryName("old path");
string filename = System.IO.Path.GetFileName("old path");
string NewFilename = "predicate" + filename;
string newlocation = System.IO.Path.Combine(folder, NewFilename );

Open in new window


this could of course be condensed into a one liner


string NewURI = System.IO.Path.Combine(System.IO.Path.GetDirectoryName("old path"), "predicate" + System.IO.Path.GetFileName("old path"));

Open in new window

0
 

Author Comment

by:toshi_
ID: 34189969
thank you a lot experts ;o)

Andre412: no worries for the typos  ;o)

toshi_
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now