Solved

how to recover all uri but the filename ?

Posted on 2010-11-22
6
414 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
Comment Utility
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
Comment Utility
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
Comment Utility
something like this:

int position = uri.LocalPath.LastIndexOf('\\');
String newPath = uri.LocalPath.Right(position) + 'otherFile.txt';
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:Andre412
Comment Utility
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
Comment Utility
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_
Comment Utility
thank you a lot experts ;o)

Andre412: no worries for the typos  ;o)

toshi_
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

7 Experts available now in Live!

Get 1:1 Help Now