Can i get access over file in FileWriter Filter of Directshow - directshow

I have read the FileWriter Filter :
" The File Writer filter can be used to write files to disc regardless of format. The filter simply writes to disc whatever it receives on its input pin, so it must be connected upstream to a multiplexer that can format the file correctly. You can create a new output file with the File Writer or specify an existing file; if the file already exists, it will be completely overwritten with the new data. "
So my question is :
I am using the FileWriter filter for writing my audio stream into the disc. Before writing the file in the disc i want to access that file , so can it be possible or should i make my own custom filter.

File writer filter does not not provide you with options to change file sharing mode while the file is being written to. Additionally, in most cases your accessing the file before it is finalized makes no sense: the files are rarely written incrementally, file finalization changes data in the middle of the file and your accessing data before the file is closed might get you bad/incomplete stream.

Roman R is right. Writers are for writing. If you need transform data - write your own Transform filter.
You can ask me directly here.

Related

Asterisk - Transfer call record not saving in database and recording filename not overriding

Before transferring call, Audio is recording correctly and overriding filename with custom filename format. Example FULLDATE_CUSTPHONE_INGROUP_TEST_AGENT
Here is the screenshot 1
But, When I transfer the call to InGroup. The file is recording, but not in exact format. And the record files are not saving in database.
Here is another screenshot for recording filename after Transferring Call to InGroup
My question is, how can I rename the filename with custom format?
Like FULLDATE_CUSTPHONE_INGROUP_TEST_AGENT
You can't rename file while it do writing.
You can stop recording, start with new filename.
Also you can add hangup header or read via AMI hangup event, after that move file as you wish.

Appending new frames to an existing DICOM file

I am working with DCMTK to modify an input DICOM file.
This is a Multi-Frame DICOM file on my disk. I need to add new frames into the PixelData element, and save the output using the same input filename.
The restriction is that I can not load the whole PixelData in memory. I would like to append new frame to the end of DICOM file, directly. Does anyone have any idea on how to do this ?
Too bad you are using DCMTK, if instead you were using GDCM, you could simply instantiate the FileStreamer class and append any Pixel Data chunk you would like:
See FileStreamer documentation.

Read from bytestream in asp

I'm wondering if it's possible to read from a bytestream without saving it.
I have a file, wich is a PDF that's in a mailbox. Through code I can access this mailbox and read out the attachements in it (the pdf's) At that point every pdf is in a bystream.
For now I just save it locally to test if my code works. But I need to work without saving the file.
Is there a way so I can get data from that file without saving. I need to process the first page and find the image in there (which is a qr code).
I have code to do this from a local file, but I want this to be directly from on of those in the bystreams.
Can I store the bytesteam in something like an object or a list of bytestreams and use that?

File upload and read from database

I am using file upload mechanism to upload file for an employee and converting it into byte[] and passing it to varBinary(Max) to store into database.
Now I what I have to do is, if any file is already uploaded for employee, simply read it from table and show file name. I have only one column to store a file and which is of type VarBinary.
Is it possible to get all file information from VarBinary field?
Any other way around, please let me know.
If you're not storing the filename, you can't retrieve it.
(Unless the file itself contains its filename in which case you'd need to parse the blob's contents.)
If the name of the file (and any other data about the file that's not part of the file's byte data) needs to be used later, then you need to save that data as well. I'd recommend adding a column for the file name, perhaps one for its type (mime type or something like that for properly sending it back to the client's browser, etc.) and maybe even one for size so you don't have to calculate that on the fly for each file (useful when displaying a grid of files and not wanting to touch the large blob field in the query that populates the grid).
Try to stay away from using the file name for system-internal identity purposes. It's fine for allowing the users to search for a file by name, select it, etc. But when actually making the request to the server to display the file it's better to use a simple integer primary key from the table to actually identify it. (On a side note, it's probably a good idea to put a unique constraint on the file name column.)
If you also need help displaying the file to the user, you'll probably want to take the approach that's tried and true for displaying images from a database. Basically it involves having a resource (generally an .aspx page, but could just as well be an HttpHandler instead) which accepts the file ID as a query string parameter and outputs the file.
This resource would have no UI (remove everything from the .aspx except the Page directive) and would manually manipulate the response headers (this is where you'd set the content type from the file's type), write the byte stream to the client, and end the response. From the client's perspective, something like ~/MyContent/MyFile.aspx?fileID=123 would be the file. (You can suggest a file name to the browser for saving purposes in the response headers, which you'd probably want to do with the file's stored name.)
There's no shortage of quick tutorials (some several years old, it's been around for a while) on how to do this with images. Just remember that there's essentially no difference from the server's perspective if it's an image or any other kind of file. All the server needs to do is send the type in the response headers and write the file's bytes to the client. How the client handles the file is up to the browser. In the vast majority of cases, the browser will know what to do (display an image, display via a plugin a PDF, save a .doc, etc.).

how to check whether a file exists before creating it

I am creating an xml file. I need to check first if the file exists or not. If the file does not exist, create it and add the data cmg from a .cs file.
If the file exists, don't create the file just add the data cmg from a .cs file.
My code looks like this:
string filename="c:\\employee.xml";
XmlTextWriter tw=new XmlTextWriter(filename,null);//null represents
the Encoding Type//
tw.Formatting=Formatting.Indented; //for xml tags to be indented//
tw.WriteStartDocument(); //Indicates the starting of document (Required)//
tw.WriteStartElement("Employees");
tw.WriteStartElement("Employee","Genius");
tw.WriteStartElement("EmpID","1");
tw.WriteAttributeString("Name","krishnan");
tw.WriteElementString("Designation","Software Developer");
tw.WriteElementString("FullName","krishnan Lakshmipuram Narayanan");
tw.WriteEndElement();
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
so next time we add data to file we need to check if the file exits and add data to xml file
and as we have made empID as a primary key, if user tries to make duplicate entry we need to avoid
Is this possible to do?
if (!File.Exists(filename))
{
// create your file
}
or
if (File.Exists(filename))
{
File.Delete(filename);
}
// then create your file
File class is in System.IO namespace (add using System.IO; to your file)
You can't append records to an XML file, you have to read the file and then rewrite it.
So, just check if the file exists, and read the records from it. Then write the file including all previous records and the new record.
Have a look at the File.Exists method here
Testing for existance of a file before attempting to create it inherently is subject to a "things change after check" race condition. Who can guarantee you that your application isn't preempted and put to sleep for a moment after you checked, someone else creates/deletes that file, your app gets to run again and does exactly the opposite of what you intended ?
Windows (as well as all UN*X variants) supports file open/create modes that allow to perform that create-if-nonexistant/open-if-existant operation as a single call.
As far as .NET goes, this means for your task (create an XML file) you'd first create a System.IO.FileStream with the appropriate modes, see http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx and then pass that stream to the XmlWriter constructor. That's safer than simply performing an "exists" check and hoping for the best.

Resources