andrew4582

ah_DeleteSafe.snippet

Mar 5th, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.28 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.     <CodeSnippet Format="1.0.0">
  4.         <Header>
  5.             <Title>AH DeleteSafe</Title>
  6.             <Shortcut>ahDeleteSafe</Shortcut>
  7.             <Description>Code snippet created on: 2/26/2011 5:01:45 PM</Description>
  8.             <Author>Andrew Hodgson</Author>
  9.             <SnippetTypes>
  10.                 <SnippetType>Expansion</SnippetType>
  11.             </SnippetTypes>
  12.         </Header>
  13.         <Snippet>
  14.             <Declarations>
  15.                 <Literal>
  16.                     <ID>type</ID>
  17.                     <ToolTip>Property type</ToolTip>
  18.                     <Default>string</Default>
  19.                 </Literal>
  20.                 <Literal>
  21.                     <ID>property</ID>
  22.                     <ToolTip>Property name</ToolTip>
  23.                     <Default>MyProperty</Default>
  24.                 </Literal>
  25.             </Declarations>
  26.             <Code Language="csharp">
  27.                 <![CDATA[        static bool DeleteSafe(string filepath) {
  28.            try {
  29.                File.Delete(filepath);
  30.                return true;
  31.            }
  32.            catch {
  33.                try {
  34.                    File.SetAttributes(filepath,FileAttributes.Normal);
  35.                    File.Delete(filepath);
  36.                    return true;
  37.                }
  38.                catch { }
  39.            }
  40.            return false;
  41.        }$end$]]>
  42.             </Code>
  43.         </Snippet>
  44.     </CodeSnippet>
  45. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment