[ 
http://issues.apache.org/jira/browse/IBATISNET-71?page=comments#action_66274 ]
     
Bob Hanson commented on IBATISNET-71:
-------------------------------------

Here is a suggested fix that will accept a url of type "file:///...", 
"file://..." or "c:\...":

                public static XmlDocument GetConfigAsXmlDocument(string 
filePath)
                {
                        XmlDocument config = new XmlDocument(); 
                        XmlTextReader reader = null; 

                        try 
                        { 
                                // ugly kludge right now but I need this to 
work today -bob
                                if (filePath != "providers.config" && 
Resources.FileExists(filePath))
                                {
                                        reader = new XmlTextReader( filePath ); 
                                
                                }
                                else
                                {
                                        reader = new 
XmlTextReader(Path.Combine(_baseDirectory, filePath)); 
                                }
                                config.Load(reader); 
                        } 
                        catch(Exception e) 
                        { 
                                throw new ConfigurationException( 
                                        string.Format("Unable to load config 
file \"{0}\". Cause : {1}", 
                                        filePath, 
                                        e.Message ) ,e); 
                        } 
                        finally 
                        { 
                                if (reader != null) 
                                { 
                                        reader.Close(); 
                                } 
                        } 

                        return config; 
                }


                public static FileInfo GetFileInfo(string filePath)
                {
                        string file = string.Empty;
                        FileInfo fileInfo = null;

                        if (filePath.ToUpper().StartsWith("FILE:///"))
                        {
                                filePath = filePath.Remove(0, 8);
                        }
                        else if (filePath.ToUpper().StartsWith("FILE://"))
                        {
                                filePath = filePath.Remove(0, 7);
                        }

                        if (Resources.FileExists(filePath)) 
                        {
                                file = filePath;
                        }
                        else
                        {
                                file = Path.Combine(_applicationBase, filePath);
                        }

                        try
                        {
                                fileInfo = new FileInfo(file);
                        }
                        catch(Exception e)
                        {
                                throw new ConfigurationException(
                                        string.Format("Unable to load file 
\"{0}\". Cause : \"{1}\"", filePath, e.Message),e);
                        }
                        return fileInfo;
                }


> Resources.GetFileInfo(string) may return incorrect value if access to 
> external location is denied
> -------------------------------------------------------------------------------------------------
>
>          Key: IBATISNET-71
>          URL: http://issues.apache.org/jira/browse/IBATISNET-71
>      Project: iBatis for .NET
>         Type: Bug
>     Reporter: Ron Grabowski
>     Assignee: Gilles Bayon
>     Priority: Minor
>      Fix For: DataMapper 1.2

>
> http://www.mail-archive.com/ibatis-dev%40incubator.apache.org/msg01176.html
> If permission is denied to the remote location:
>  Resources.GetFileInfo("c:/does_not_have_permission/sqlMap.config")
> and there is a file called sqlMap.config in the base directory of my 
> application:
>  /sqlMap.config
> File.Exists will return false if permission to the path is denied (see 
> mail-archive.com post for more info):
>  if (!File.Exists(path)) 
>  {
>   file = Path.Combine(_applicationBase, path);
>  }
>  else
>  {
>   file = path;
>  }
> A FileInfo object for the local sqlMap.config will be returned.
> I haven't actually tested this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to