public virtual string CreateDirectory(string table, string dir, string pathId, SqlConnection conn) { SqlConnManager.IsConnected(conn); if (!FileTableExists(table, conn)) { throw new Exception("Table does not exists or is not a FileTable."); } var CreateDirectoryQry = "INSERT INTO {0} (name, is_directory)" + " OUTPUT Inserted.path_locator.ToString()" + " VALUES (@dir, 1)"; var qry = string.Format(CreateDirectoryQry, table); var cmd = new SqlCommand(qry, conn); cmd.Parameters.Add(new SqlParameter("@dir", dir)); if (!string.IsNullOrWhiteSpace(pathId)) { pathId = HierarchyBuilder.NewChildHierarchyId(pathId); CreateDirectoryQry = "INSERT INTO {0} (name, is_directory, path_locator)" + " OUTPUT Inserted.path_locator.ToString()" + " VALUES (@dir, 1, @pathId)"; cmd.CommandText = string.Format(CreateDirectoryQry, table); cmd.Parameters.Add(new SqlParameter("@pathId", pathId as object)); } pathId = cmd.ExecuteScalar() as string; return(pathId); }
public virtual SqlHierarchyId CreateDirectory(string table, string dir, SqlHierarchyId pathId, SqlConnection conn, bool pipeToOutput = false) { SqlConnManager.IsConnected(conn); if (!FileTableExists(table, conn)) { throw new Exception("Table does not exists or is not a FileTable."); } var CreateDirectoryQry = "INSERT INTO {0} (name, is_directory)" + " OUTPUT Inserted.path_locator" + " VALUES (@dir, 1)"; var qry = string.Format(CreateDirectoryQry, table); var cmd = new SqlCommand(qry, conn); cmd.Parameters.Add(new SqlParameter("@dir", dir)); if (!pathId.IsNull) { pathId = HierarchyBuilder.NewChildHierarchyId(pathId); CreateDirectoryQry = "INSERT INTO {0} (name, is_directory, path_locator)" + " OUTPUT Inserted.path_locator" + " VALUES (@dir, 1, @pathId)"; cmd.CommandText = string.Format(CreateDirectoryQry, table); var param1 = new SqlParameter("@pathId", pathId) { UdtTypeName = Constants.HierarchyId }; cmd.Parameters.Add(param1); } pathId = (SqlHierarchyId)(cmd.ExecuteScalar() ?? SqlHierarchyId.Null); if (pipeToOutput) { PipeFile(table, pathId, conn); } return(pathId); }
public Guid CreateFile(string table, string fileName, SqlHierarchyId pathId, byte[] data, SqlConnection conn) { SqlConnManager.IsConnected(conn); if (!FileTableExists(table, conn)) // This is used to prevent SQL injection { throw new Exception("Table does not exists or is not a FileTable."); } if (pathId.IsNull) { pathId = HierarchyBuilder.NewChildHierarchyId(SqlHierarchyId.Null); } var insertQry = "INSERT INTO {0} (name, file_stream, path_locator) " + " OUTPUT Inserted.stream_id" + " VALUES (@fileName, @data, @pathId)"; var qry = string.Format(insertQry, table); var cmd = new SqlCommand(qry, conn); cmd.Parameters.Add(new SqlParameter("@fileName", fileName)); cmd.Parameters.Add(new SqlParameter("@data", data)); cmd.Parameters.Add(new SqlParameter("@pathId", pathId) { UdtTypeName = Constants.HierarchyId }); var streamId = (Guid)cmd.ExecuteScalar(); PipeScalar(SqlDbType.UniqueIdentifier, streamId); return(streamId); }
public string CreateFile(string table, string path, byte[] data, SqlConnection conn) { var file = Path.GetFileName(path); var dir = Path.GetDirectoryName(path); var pathId = DirectoryExists(table, dir, conn); if (string.IsNullOrWhiteSpace(pathId)) { pathId = CreateDirectory(table, dir, conn); } var hierarchyId = FileTableRepo.CreateFile(table, file, HierarchyBuilder.NewChildHierarchyId(pathId), data, conn); return(hierarchyId); }
public string CreateFile(string table, string fileName, string pathId, byte[] data, SqlConnection conn) { SqlConnManager.IsConnected(conn); if (!FileTableExists(table, conn)) { throw new Exception("Table does not exists or is not a FileTable."); } if (string.IsNullOrWhiteSpace(pathId)) { pathId = HierarchyBuilder.NewChildHierarchyId(null); } var insertQry = "INSERT INTO {0} (name, file_stream, path_locator) " + " OUTPUT Inserted.path_locator.ToString()" + " VALUES (@fileName, @data, HierarchyId::Parse(@pathId))"; var qry = string.Format(insertQry, table); var cmd = new SqlCommand(qry, conn); cmd.Parameters.Add(new SqlParameter("@fileName", fileName)); cmd.Parameters.Add(new SqlParameter("@data", data)); cmd.Parameters.Add(new SqlParameter("@pathId", pathId)); var hierarchyid = cmd.ExecuteScalar() as string; return(hierarchyid); }