I'm hoping there is a built in .NET method to do this, but I'm not finding it.  I have two paths that I know to be on the same root drive, I want to be able to get a relative path from one to the other.  string path1 = @"c:\dir1\dir2\"; string path2 = @"c:\dir1\dir3\file1.txt"; string relPath = MysteryFunctionThatShouldExist(path1, path2);  // relPath == "..\dir3\file1.txt"   Does this function exist?  If not what would be the best way to implement it?
There's a part in my apps that displays the file path loaded by the user through OpenFileDialog. It's taking up too much space to display the whole path, but I don't want to display only the filename as it might be ambiguous. So I would prefer to show the file path relative to the assembly/exe directory.  For example, the assembly resides at C:\Program Files\Dummy Folder\MyProgram and the file at C:\Program Files\Dummy Folder\MyProgram\Data\datafile1.dat then I would like it to show .\Data\datafile1.dat. If the file is in C:\Program Files\Dummy Folder\datafile1.dat, then I would want ..\datafile1.dat. But if the file is at the root directory or 1 directory below root, then display the full path.   What solution would you recommend? Regex?  Basically I want to display useful file path info without taking too much screen space.  EDIT: Just to clarify a little bit more. The purpose of this solution is to help user or myself knowing which file did I loaded last and roughly from which directory was it from. I'm using a readonly textbox to display the path. Most of the time, the file path is much longer than the display space of the textbox. The path is supposed to be informative but not important enough as to take up more screen space.  Alex Brault comment was good, so is Jonathan Leffler. The Win32 function provided by DavidK only help with part of the problem, not the whole of it, but thanks anyway. As for James Newton-King solution, I'll give it a try later when I'm free.
It has been said that RSA uses a modulus product of two prime numbers for security reasons. But does RSA even work correctly if we allow composite integers instead?  I think that the answer is "NO".  Define “work correctly” as:   allows encryption and decryption to be carried out as in normal RSA, yielding the original message (message padding and unpadding can remain unspecified, or absent as in texbook RSA); a security level can be given in terms of the key generation process (which may have alternate requirements to testing that $p$ and $q$ are prime). How can I make a plane's edges taper inwards? How can I deform one edge or multiple edges of a plane or cube so they are tapered in and rounded equally? For $q, p$ odd primes such that $p \neq q$, there is not primitive root modulo $pq$. Is there a public API for Stack Overflow? Wrong user when logging into Data Explorer I think I'm having the same issue as reported in this question:    When I log into SEDE with the same OpenID account I use for SE, a different user comes up ("James Wiseman" on Stack Exchange and "adsense" in Data Explorer).  Is there anything I can do personally to rectify this, or must I rely on the admins? Getting MTP enabled devices to work with Ubuntu? Why is the PHP version different in phpinfo() and CLI? I realized that there is a miss matching between the PHP version reported by phpinfo() and php -v (in the CLI).  phpinfo():  5.5.24 php -v: 5.6.9   I am working on a Mac OS X 10.10 (Yosemite) and installed a library (php-version) to try to manage the PHP versions.  It reports me 3 different versions installed on my laptop:    5.4.41   5.5.25 * 5.6.9   I would like to set the same version of PHP in both Apache and CLI.  How can I tell Apache which PHP version use?  I tried to write this line in my httpd.conf:  LoadModule php5_module    /usr/local/opt/php56/libexec/apache2/libphp5.so   Then:  sudo apachectl restart   But all this not solve the problem… In my PHP info I still have: 5.5.24 Using Sequence to delete a part of an expression Prove that $\lim_{n\to\infty}a_n\le \lim_{n\to\infty}b_n$ How should a physics student study mathematics? Note: I will expand this question with more specific points when I have my own internet connection and more time (we're moving in, so I'm at a friend's house).  This question is broad, involved, and to some degree subjective.  (I started out as a physics-only student, but eventually decided to add a mathematics major. I am greatly interested in mathematics; the typical curriculum required for physics students is not deep or thorough enough; mathematics is more general (that means work!); and it only requires a few more classes. Naturally, I enjoy  immensely.)  This question asks mainly of undergraduate-level study, but feel free to discuss graduate-level study if you like.  Please do not rush your answer or try to be comprehensive. I realize the StackOverflow model rewards quick answers, but I would rather wait for a thoughtful, thorough (on a point) answer than get a fast, cluttered one. (As you probably know,  produces clear, useful writing; and a properly-done comprehensive answer would take more than a reasonable amount of time and effort.) If you think an overview is necessary, that is fine.  For a question this large, I think the best thing to do is focus on a specific area in each answer.    Update: To Sklivvz, Cedric, Noldorin and everyone else: I had to run off before I could finish, but I wanted to say I knew I would regret this; I was cranky and not thinking clearly, mainly from not eating enough during the day. I am sorry for my sharp responses and for not waiting for my reaction to pass. I apologize.  Re: Curricula:   Please note that I am not asking about choosing your own curriculum in college or university. I did not explicitly say that, but several people believed that was my meaning. I will ask more specific questions later, but the main idea is how a physics student should study mathematics (on his or her own, but also by choosing courses if available) to be a competent mathematician with a view to studying physics.  I merely mentioned adding a mathematics major to illustrate my conclusion that physics student need a deeper mathematical grounding than they typically receive.   And now I have to run off again. How can continue the equation of the rectangle red in next line?   \documentclass[11pt,a4paper,twocolumn]{article}  ...  \begin{equation*}     \left| \dot{r} \right| =     \sqrt{{- \, {e}^{-t} \left( \cos t + \sin t \right)}^{2} \, + \, {{e}^{-t} \left( \cos t + \sin t \right)}^{2} \, + \, {(- \, {e}^{-t})}^{2}} \end{equation*} What are the integer solutions to $a^{b^2} = b^a$ with $a, b \ge 2$ I saw this in quora.  What are all the integer solutions to $a^{b^2} = b^a$ with $a, b \ge 2$?  Solutions I have found so far:  $a = 2^4 = 16, b = 2, a^{b^2}  = 2^{4\cdot 4} =2^{16}, b^a = 2^{16} $.  $a = 3^3, b = 3, a^{b^2} = 3^{3\cdot 9} =3^{27}, b^a = 3^{3^3} =3^{27} $.  In the general case, $a$ and $b$ have the same set of prime divisors, so let $a =\prod_P p_i^{a_i}$, $b =\prod_P p_i^{b_i} $ with each $a_i \ge 1, b_i \ge 1$.  $b^a =b^{\prod p_i^{a_i}} =(\prod p_j^{b_j})^{\prod p_i^{a_i}} =\prod p_j^{b_j\prod p_i^{a_i}} $  $a^{b^2} =a^{\prod p_i^{2b_i}} =(\prod p_j^{a_j})^{\prod p_i^{2b_i}} =\prod p_j^{a_j\prod p_i^{2b_i}} $  Therefore, for each $p_j$, $b_j\prod p_i^{a_i} =a_j\prod p_i^{2b_i} $.  I haven't gotten any further than this.  I conjecture that there are no other solutions. Is "Michael here" correct? Is it always possible to find the limit of a function without using  or ?  For example,   $$\lim_{x\to0}\frac{\tan x-x}{x^3}$$  $$\lim_{x\to0}\frac{\sin x-x}{x^3}$$  $$\lim_{x\to0}\frac{\ln(1+x)-x}{x^2}$$  $$\lim_{x\to0}\frac{e^x-x-1}{x^2}$$  $$\lim_{x\to0}\frac{\sin^{-1}x-x}{x^3}$$  $$\lim_{x\to0}\frac{\tan^{-1}x-x}{x^3}$$ Android: fragments overlapping issue idempotents acting as local identities Let $R$ be a ring with unity (not necessarily commutative) and $I$ an ideal of $R$.  Suppose that for every element $a \in I$ there exists an element $c\in I$ such that $ac=a$. Note that $c$ is related to $a$. Now we have the following question:  Can we say that  for every element  $a\in I$ there exists an idempotent element $c\in I$ such that $ac=a$?    Of course we have many examples such that the answer is true for them but in general  we don't know. What is the logical form of the definition of validity? My text book gives the definition of validity as "An argument is valid IFF if the premises are true, then the conclusion must be true". Using a conditional elimination on the RHS of the IFF yields "An argument is valid IFF the premises are false or the conclusion is true".   Yet, this seems strange to me. Am I doing something incorrect with my manipulation or is this definition actually true? Surely the criteria for a valid argument goes beyond a false set of premises or a true conclusion. Why don't the colonists wear spacesuits in Alien: Covenant? In the beginning of the Alien: Covenant movie, a group of colonists from the main ship make a landing on an unknown planet, which they found out accidentally after ship has been bombarded by an unknown wave from a star collapse and what bothers me, is that they don't wear any spacesuits, any protective gear, any air filter systems, just nothing.  Is that really the way future space expeditions gonna explore new possible planets presumed as possible habitable homes for humanity?  Every 5th grader knows, from the biology school lessons, that water, air, and even earth itself contains and gives life to a thousands of viruses, bacteria, and microorganisms.  You can breathe in bacteria, or virus, and be dead in a seconds.  Do film makers really suppose we will take it as realistic depiction of extraterrestrial expedition?   Reality check just screams out loud.  What do you think can be their motivation for such a decision? Display number with leading zeros Given: a = 1 b = 10 c = 100  How do I display a leading zero for all numbers with less than two digits? This is the output I'm expecting: 01 10 100 How to select the nth row in a SQL database table?