473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I get this?

Hello,

I have a string like this:
~/Uploads/18/MyImage.png

Now I only need the directory like this:
~/Uploads/18/

What's the best way to do this?
Or how can I do this in C#?

Thanks!
Nov 17 '05 #1
3 905
try:

string strPath="~/Uploads/18/MyImage.png";

//get your directory in a string
string strDirectory=strPath.Substring(0,13);
//where 0 is the start index and 13 is the length of
//the string you want

hope that helps,

-----Original Message-----
Hello,

I have a string like this:
~/Uploads/18/MyImage.png

Now I only need the directory like this:
~/Uploads/18/

What's the best way to do this?
Or how can I do this in C#?

Thanks!
.

Nov 17 '05 #2
string s = "~/Uploads/18/MyImage.png";
string s = s.SubString( 0, s.LastIndexOf( "/" ) - 1 ); (since it is a path,
you are guaranteed to not have any / in the filename...I think)

bill

"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news2.tilbu1.nb.home.nl...
Hello,

I have a string like this:
~/Uploads/18/MyImage.png

Now I only need the directory like this:
~/Uploads/18/

What's the best way to do this?
Or how can I do this in C#?

Thanks!

Nov 17 '05 #3
http://www.aspnetpro.com/NewsletterA...200307bn_l.asp

Imports System.IO

Response.Write(Path.GetDirectoryName("~/Uploads/18/MyImage.png"))

outputs:
~\Uploads\18

HTH,
Greg
"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news2.tilbu1.nb.home.nl...
Hello,

I have a string like this:
~/Uploads/18/MyImage.png

Now I only need the directory like this:
~/Uploads/18/

What's the best way to do this?
Or how can I do this in C#?

Thanks!

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company...
5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
2
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form...
2
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") ||...
0
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.