从共享网络文件夹访问文件

时间:2016-03-22 12:47:37

标签: .net nfs

我已经创建了一个nfs共享文件夹,并且从.net Web应用程序我将从该共享文件夹返回一个文件。但我无法归还它。而当我在C:\中创建一个Windows文件夹时,我能够将文件返回给应用程序。

代码如下:

 public FilePathResult GetSSLRawFile(SearchPage searchpage)
        {
           string sourceFile="";
           List<_LocationDetails> Locationlist = PopulateLocationList();
           DateTime dt = searchpage.strSslDate;
           string date = dt.ToString("dd-MM-yyyy");
           string strLocName = searchpage.strSSLLocName;
           string strLocID = null;
           for (int k = 0; k < Locationlist.Count; k++)
           {
               //if location id present in table T090Locations then display its ID other wise display not available
               if (Locationlist[k].strLocName == strLocName)
               {
                   strLocID = Locationlist[k].strLocID;
                   break;
               }
           }
           //if location ID is not available then display message  "File Not Found"
           if (null == strLocID) 
            {
                string strAttpath = "c:\\MI_GUI_Att\\Readme.txt";
                string ErrMsg = "File Not Found ";
                //If Error Message present than write the content to a file and return it.
                System.IO.StreamWriter file = new System.IO.StreamWriter(strAttpath);
                file.WriteLine(ErrMsg);
                file.Close();
                return File(strAttpath, " ", "Readme.txt");
            }
            try     
            {
                sourceFile = System.Configuration.ConfigurationManager.AppSettings["SSLRAWFILEPATH"].ToString(); //getting this path from web.config file
            }
            catch (Exception e) //return and display proper message in gui
            {
                ViewBag.DBError = true;
                ViewBag.ErrMsg = "Recheck 'SSLRAWFILEPATH' parameter in Web.config";
                string strAttpath = "c:\\MI_GUI_Att\\Readme.txt";                
                //If Error Message present than write the content to a file and return it.
                System.IO.StreamWriter file = new System.IO.StreamWriter(strAttpath);
                file.WriteLine(ViewBag.ErrMsg);
                file.Close();  
                return File(strAttpath, " ", "Readme.txt");

            }

            string destFile = sourceFile + "\\" + strLocID + "\\" + date + "\\" + searchpage.strSslFileName;
            if (false == System.IO.File.Exists(destFile))
            {
                string strAttpath = "c:\\MI_GUI_Att\\Readme.txt";
                string ErrMsg = "File Not Found on path " + destFile;
                //If Error Message present than write the content to a file and return it.
                System.IO.StreamWriter file = new System.IO.StreamWriter(strAttpath);
                file.WriteLine(ErrMsg);
                file.Close();
                return File(strAttpath, " ", "Readme.txt");

            }
            return File(destFile, " ", searchpage.strSslFileName); //Returning file name
       }

0 个答案:

没有答案