/// <summary> /// This method adds files to the repository /// </summary> /// <param name="Item">SPListItem</param> /// <param name="TargetPID">string</param> public static string AddItemToRepository(SPWeb Web, SPListItem Item, string TargetPID) { string _ObjectPID = string.Empty; SPListItem ObjItem = Item; //Getting the namespace format string Namespace = string.Empty; using (MySiteRepositorySettings ObjSettings = new MySiteRepositorySettings()) { SPListItem settings = ObjSettings.GetRepositorySettings(SPContext.Current.Web.Title); if (settings != null) { Namespace = settings["Namespace Format"].ToString().Replace("{listname}",Item.ParentList.Title.Replace(" ", "")); } } //Add file to the repository -------------------------------------------------------------------------------- SPFile file = ObjItem.File; if (file != null) { //MEtabasepath //string METABASEPATH = "IIS://" + Web.Site.HostName + "/MimeMap"; //URL //string url = Web.Url + '/' + file.Url; //MimeType string mimeType = MimeTypeHelper.GetContentType(file.Name);//MimeType.GetMimeTypeForExtension(METABASEPATH, Path.GetExtension(file.Name)); //Namespace string nameSpace = Web.Title + "-" + ObjItem.ParentList.Title; //Item Title string itemTitle = ObjItem.Name.Trim(); //Skip Virus Scan byte[] content = file.OpenBinary(SPOpenBinaryOptions.SkipVirusScan); string author = "Unknown author"; if ((file.SourceFile != null) && !String.IsNullOrEmpty(file.SourceFile.Name)) { author = file.SourceFile.Name.Trim(); } else if ((file.Author != null) && !String.IsNullOrEmpty(file.Author.Name)) { author = file.Author.Name.Trim(); } HydraServiceFedoraExt hydraService = new HydraServiceFedoraExt(); _ObjectPID = hydraService.DepositSimpleContentObject(Namespace, itemTitle, TargetPID, content, mimeType, author, author); //PolicyDS policyDS = new PolicyDS(); //policyDS.Xml = GetPolicyDS(hydraService.Pid,author); //hydraService.AppendMetaData("POLICY", "XACML Policy Datastream", policyDS); //Updating operation status for the exported list item UpdateSourceItem(ObjItem, Web, _ObjectPID); //Adding an entry in Published Documents Log UpdatePublishedDocumentsLog(Web, _ObjectPID, ObjItem); } return _ObjectPID; }
protected override void OnLoad(EventArgs e) { string _pid = string.Empty; SPWeb ObjWeb = SPContext.Current.Web; SPList ObjList = null; SPListItem item = null; if (Request.QueryString["item"] != null) { _itemId = Request.QueryString["item"].ToString(); } if (Request.QueryString["listn"] == null) { if (Request.QueryString["list"] != null) { _listId = Request.QueryString["list"].ToString(); } ObjList = ObjWeb.Lists[new Guid(_listId)]; item = ObjList.Items.GetItemById(Convert.ToInt32(_itemId)); _pid = item["Persistent ID"].ToString(); } else { ObjList = ObjWeb.Lists[Request.QueryString["listn"]]; item = ObjList.Items.GetItemById(Convert.ToInt32(_itemId)); _pid = item["Persistent ID"].ToString(); } HydraServiceFedoraExt hydraService = new HydraServiceFedoraExt(); Response.Clear(); Response.Buffer = true; Response.ContentType = item["Content MimeType"].ToString(); Response.AddHeader("content-disposition", "attachment; filename=" + _pid + SPHelper.GetFileExtension(item["Content MimeType"].ToString())); Response.BinaryWrite(hydraService.GetObjectHydra(_pid)); Response.Flush(); Response.End(); }
/// <summary> /// DepositDocument. Uses the Hydranet code library to construct a Hydra profile Fedora repository object /// and uses the same library to send it to the repository. /// </summary> private void DepositDocument() { if (_file != null) { using (SPWeb site = SPContext.Current.Web) { string url = site.Url + '/' + _file.Url; string nameSpace = System.Configuration.ConfigurationManager.AppSettings["FedoraObjectNamespace"]; HydraServiceFedoraExt hydraService = new HydraServiceFedoraExt(nameSpace, _itemTitle, HttpContext.Current.User.Identity.Name, ":1"); byte[] content = null; content = _file.OpenBinary(SPOpenBinaryOptions.SkipVirusScan); // virusscan could cain the server on a large file, files containing viruses should never have been allowed onto sharepoint in the first place anyway if (ckShowDC.Checked) { hydraService.AppendDCMetaData(GetDC()); } if (ckShowBasicMODs.Checked || ckshowIPMODs.Checked) { hydraService.AppendDescriptionMetaData(GetMODS()); } hydraService.AppendContent(content, _mimeType); hydraService.AddRelsExtMetaData(System.Configuration.ConfigurationManager.AppSettings["FedoraPublishQueuePID"]); hydraService.DepositContentObject(); _successfulUpload = true; ReportSuccess(); } } }