2012-05-29 28 views
0

我需要能夠上傳文件上傳中的KML文件,使用XSLT將其轉換爲GML,然後將其保存到我的SQL 2008數據庫中。我不知道該怎麼做。任何幫助表示讚賞。如何在文件上傳中使用XSLT ASP.Net MVC

這裏是我的代碼至今:

public ActionResult Create(GeoRegion georegion, HttpPostedFileBase Polygon) 
    { 
     if (ModelState.IsValid) 
     { 

      if (Polygon.ContentLength > 0) 
      { 
       var fileName = Path.GetFileName(Polygon.FileName); 
       var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); 
       Polygon.SaveAs(path); 

      } 




      db.GeoRegions.Add(georegion); 
      db.SaveChanges(); 
      return RedirectToAction("Index"); 
     } 

     return View(georegion); 
    } 
+0

如果您還沒有這樣做的話,我建議你閱讀[文章](HTTP:// spanring .eu/blog/2005/12/11/kml2gml /)由Christian Spanring提供。 – kush

回答

0
// Create the XslCompiledTransform object 
var transform = new XslCompiledTransform(); 

// Load the stylesheet file 
transform.Load(xslFilePath);     

// Transform the XML file and store the output 
transform.Transform(sourceFilePath, targetFilePath);  

http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx

+0

如何將轉換後的xml保存到數據庫? – user1382770

+0

這裏有一個相當複雜的方法:http://mscerts.programming4.us/sql_server/sql%20server%202008%20%20%20developing%20custom%20managed%20database%20objects%20%28part%203%29 %20-%20developing%20managed%20user定義的%20functions.aspx。但是,[研究輸出選項](http://msdn.microsoft.com/en-us/library/0610k0w4.aspx)針對XslCompiledTransform。據推測,你希望將輸出存儲在SQL Server數據庫的XML字段中。使用Stream或TextWriter輸出選項,並將結果輸出寫入新的數據庫字段。 –