关于FileTable是什么,请猛击如下链接:http://technet.microsoft.com/zh-cn/library/ff929144(v=SQL.110).aspx;如您已知道,请跳过。

关于如何启用FileTable功能,请猛击如下链接:http://technet.microsoft.com/zh-cn/library/gg509097.aspx

关于如何创建、修改和删除FileTable,请猛击如下链接:http://technet.microsoft.com/zh-cn/library/gg509088.aspx

欲了解更多FileTable特性及支持,请点击以上链接页面页底的相关任务部分(如图):

在上面的截图中用红色框框圈出的部分,将是本文的重点部分。在新建FileTable后,右击并选择“浏览FileTable目录”,如下图:

没错,也许您已想到,这就是所谓的FileTable支持Windows I/O API操作,这样我们就可以利用System.IO命名空间下的FileInfo类中的Move、Copyto等函数实现利用FileTable上传文件的功能。下面我们将实现如何在C#程序中实现这点:

1.首先要获取到FileTable表的RootPath(也就是上图中圈出的网络路径),就这一点我们可以T-SQL中的函数FileTableRootPath(),比如说我建的FileTable名为MyFirstFileTable,那么T-SQL如下便可获取其RootPath:

 select FileTableRootPath('MyFirstFileTable') as Path

2.RootPath获取后我们就可以在C#程序中实现了,如下代码:

         /// <summary>
/// Upload files by FileTable
/// </summary>
/// <param name="strFilePath">the path of target file</param>
public void UploadbyFileTable(string strFilePath)
{
if (!File.Exists(strFilePath))
return;
FileInfo file = new FileInfo(strFilePath);
string strDBConnection = "Server=your server name/IP,initial catalog=your database name,User id=your id,passord=your password";
string strFileTableName = "your FileTable's name";
string strRootPath = GetFileTableRootPath(strDBConnection, strFileTableName);
if (File.Exists(Path.Combine(strRootPath, file.Name)))
{
return;
}
file.MoveTo(Path.Combine(strRootPath, file.Name));
} /// <summary>
/// Get your Filetable's RootPath
/// </summary>
/// <param name="strDBConnection">your DB connection string</param>
/// <param name="strFileTableName">your FileTable name</param>
/// <returns>your Filetable's RootPath</returns>
public string GetFileTableRootPath(string strDBConnection,string strFileTableName)
{
string strRootPath = string.Empty;
try
{
SqlConnection sqlCon = new SqlConnection(strDBConnection);
sqlCon.Open();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("select FileTableRootPath('{0}') as [path]", strFileTableName);
SqlCommand sqlCmd = new SqlCommand(sb.ToString(), sqlCon);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
sqlDa.Fill(dt);
strRootPath = dt.Rows[][].ToString();
sqlDa.Dispose();
sqlCmd.Dispose();
sqlCon.Close();
}
catch(Exception e)
{
throw e;
}
return strRootPath;
}

这样就实现了利用FileTable上传文件的功能。到最后,您发现是不是很简单呢?
欢迎您积极提出建议和疑问,我会尽自己的力量给您满意的答复,O(∩_∩)O谢谢

SQL2012之FileTable与C#的联合应用的更多相关文章

  1. Dynamics CRM 之ADFS 使用 WID 的独立联合服务器

    ADFS 的使用 WID 的独立联合服务器适用于自己的测试环境,常用的就是在虚机中使用. 拓扑图如下: wID:联合身份验证服务配置为使用 Windows 内部数据库

  2. Dynamics CRM 之ADFS 使用 WID 的联合服务器场

    使用 WID 的联合服务器场 默认拓扑 Active Directory 联合身份验证服务 (AD FS) 是联合服务器场,使用 Windows 内部数据库 (WID). 在这种拓扑, AD FS 使 ...

  3. Hibernate(5)—— 联合主键 、一对一关联关系映射(xml和注解) 和 领域驱动设计

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: One to One 映射关系 一对一单向外键(XML/Annotation) 一对一双向外键关联(XML/A ...

  4. Federated Identity Pattern 联合身份模式

    Delegate authentication to an external identity provider. This pattern can simplify development, min ...

  5. [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合

    [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合 Datasets can often contain components of that require differe ...

  6. SQL联合查询:子表任一记录与主表联合查询

    今天有网友群里提了这样一个关于SQL联合查询的需求: 一.有热心网友的方案: 二.我的方案: select * from ( select a.*,(select top 1 Id from B as ...

  7. Dynamics CRM 之ADFS 使用 SQL Server 的联合服务器场

    此拓扑用于 Active Directory 联合身份验证服务 (AD FS) 不同于使用 Windows 内部数据库 (WID) 部署拓扑,因为不会将数据复制到每台联合服务器场中的联合身份验证服务器 ...

  8. Dynamics CRM 之ADFS 使用 WID 和代理的联合服务器场

    为此部署拓扑 Active Directory 联合身份验证服务 (AD FS) 等同于联合服务器场与 Windows 内部数据库 (WID) 拓扑中,但它将代理服务器计算机添加到外围网络,以支持外部 ...

  9. SQL Server 2012 新特性:FileTable

    FileTable是基于FILESTREAM的一个特性.有以下一些功能: 一行表示一个文件或者目录. 每行包含以下信息: file_Stream流数据,stream_id标示符(GUID). 用户表示 ...

随机推荐

  1. maya 操作自我整理(一)

    绘制曲线时的点的控制 当我们在使用CV Curve Tool或者EP Curve Tool创建NURBS曲线的过程中,按下"Insert"键,配合键盘上的上.下箭头方向键,可以自由 ...

  2. Java---基于TCP协议的相互即时通讯小程序

    这是几年前,新浪的一个面试题~要求是3天之内实现~ 通过TCP 协议,建立一个服务器端. 通过配置服务器端的IP和端口: 客户端之间就可以相互通讯~ 上线了全部在线用户会收到你上线的通知. 下线了全部 ...

  3. 检测WIfi是否打开

    引入SystemConfiguration库并添加头文件: #import <SystemConfiguration/SystemConfiguration.h> 代码如下:     NS ...

  4. apply和call详解

    1.        apply和call的区别在哪里 2.        什么情况下用apply,什么情况下用call 3.        apply的其他巧妙用法(一般在什么情况下可以使用apply ...

  5. [Git] Github上传新repository后自动合并

    原因是新repository中有个与老repository一模一样的名字为".git"的隐藏文件夹,删去后即可: 将整个工程直接复制粘贴出此错误...好蠢: Github控制项目的 ...

  6. STL之map、multimap

    map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺序排列.元素的插入过程是按照排序规则 ...

  7. poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14106   Ac ...

  8. AutoLayout--masonry使用

        [label1 mas_makeConstraints:^(MASConstraintMaker *make) {         //使左边间距为         make.left.equ ...

  9. DevExpress控件 GridControl 单元格编辑 回车

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. javascript正则表达式简述

    compile 编译或改变字符串,参数跟new RegExp相同 var patt = /man/g; var str = "man and woman"; str.replace ...