Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am upload photograph using file upload and saved photo in server and i also saved image path in database. i want to bind image to image control using path retrieve from database.


following is the path which is retrieve.

"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg"

i want to remove a string "D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\"

after that i want to bind image using remaining path i.e. "Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg". please help me to solve my isssue.


Thanks
Manohar
Posted
Comments
vinayakJJ 5-Aug-13 7:46am    
do you want this string Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg to be cut from this D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg string
am i correct
Manohar Khillare 5-Aug-13 7:50am    
yes

C#
string test=@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg";
           int index=test.IndexOf("Doctor");
           string sub = test.Substring(index, test.Length - index);
           MessageBox.Show(sub);
 
Share this answer
 
Comments
Manohar Khillare 5-Aug-13 8:22am    
its working partially
i want ~\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg";
How about that one
C#
string notSoLongPath = givenPath.SubString(
    (@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\").Length
);
It uses the Substring[^] method to extract a portion of a string. To know what portion, the String.Length[^] property can deliver the length of a given string, in this case of a hard-coded string literal.

Remember that in general, hard-coding any paths is not a good idea. Instead, store the path in your application's resources.
 
Share this answer
 
v2
Hi,
Try this

C#
string s = @"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg";
s = s.Replace(@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\", "");


Hope it helps.
 
Share this answer
 
Use Server.MapPath for upload image.....:)

C#
imgProfileUpload.SaveAs(Server.MapPath("~/Doctor/DOCUMENTS/1326/Photograph/Penguins.jpg");
 
Share this answer
 
Comments
Manohar Khillare 5-Aug-13 7:48am    
i am already use Server.MapPath to save image . i want to bind image to image control using path Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg
Manohar Khillare 5-Aug-13 7:49am    
actully it retrive the path as "D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg"
Nirav Prabtani 5-Aug-13 7:51am    
have you retrieve path from database??
Manohar Khillare 5-Aug-13 7:53am    
yes
Nirav Prabtani 5-Aug-13 7:56am    
use server.mappath when you store image path in database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900