DropNet Chunked Upload - c#

The current version of DropNet (1.8.2.0) seems to be handling the REST portion of things fine, but when I call the final CommitChunkedUpload to complete the upload, I get a dropbox error indicating that the path parameter was in the wrong format.
client.CommitChunkedUpload(upload, "/" + FolderName + "/" + FileName, true);
Leaving off the folder or changing where I want the file to be saved does not resolve things. If I leave off the filename then it tries to save the folder as a file with no contents but does not throw the error.
Am I missing something in the syntax?

Related

Trying to upload a PDF file using ASP.NET MVC is causing an error "Object reference not set to an instance of an object"

I am trying to upload a PDF file to a folder and save the file path to the database in ASP.NET MVC. I can use this same method to save a JPG file while it is throwing an error for a PDF file.
Am I missing out anything?
This is my code:
DirectoryInfo dir = new DirectoryInfo(HttpContext.Server.MapPath("~/LoanDocuments/Uploads/"));
if (!dir.Exists)
{
dir.Create();
}
// Uploading PDF and saving to database
// Extract PDF File Name.
string fileName = initiateLoanRequest.Firstname + initiateLoanRequest.Surname + Loan_RequestID; //The filename will be FirstnameSurnameLoan_RequestID
// Set the PDF File Path.
string filePath = "/LoanDocuments/Uploads/" + fileName + ".pdf";
// Save the uploaded document in Folder.
loan_Document.SaveAs(Server.MapPath(filePath));
What am I missing out in this? It works well when I used same code in another module for JPG files.
Please note that the loan_Document is posted as HttpPostedFileBase loan_Document.
Issue resolved. The Posted file name I am sending from the View is different from the postedfile name I am using at the Controller. So using the same names resolved the issue.
Thank you

Unable to delete file after moving in c#

I am trying to delete a file but I am getting error message (access denied) even though I have full permission. Initially my file will be in my root folder. First I am renaming the file and then moving the file to a different folder (outside of root folder) as below.
System.IO.File.Move(strPhysicalFolder+ tpfile,strPhysicalFolder+fName);
System.IO.File.Move(strPhysicalFolder + fName, filePath + fName);
System.IO.File.SetAttributes(filePath + fName, FileAttributes.Normal);
Now whenever I try to delete the file I am getting an error (access denied).
Below is my code:
string strFileFullPath = srcPath + filename;
if (System.IO.File.Exists(strFileFullPath))
{
System.IO.File.Delete(strFileFullPath);
}
strFileFullPath contains the path to the file I am not able to delete. Do I need to do anything before deleting (setting attribute)? Any help would be appreciated. Thank you.
Sounds daft but it will probably be the permissions on the folder.
maybe something like the following:
System.IO.File.SetAttributes(strFileFullPath, FileAttributes.Normal);
System.IO.File.Delete(strFileFullPath);

File.Exists is returning false even though I can see the file C#

Issue
I have a function which lets the user edit an image when they do this I save this new image to a file to which they I save to the database etc ...
The issue comes as when I try and look for the file I just saved it says it does not exist but it does?
Code
Here I am saving the new file to the TEMP folder:
string newFullTempFolderURL = Path.Combine(Global.TempFolder, newFullFileName + ".png");
_image.Save(newFullTempFolderURL, System.Drawing.Imaging.ImageFormat.Png);
At this point when I check the folder the file is in the folder with the new image.
Then when I go on to uploading the file to the server (Using BITS) I do a check to make sure the file exists:
if (File.Exists(Path.Combine(Global.TempFolder + "\\" + newFullFileName)))
{
}
This then returns false (Not exists) when i can see the file with my own eyes!
Anyone had this same issue?
EDIT1:
newFullFileName already contains .png:
string newFullFileName = string.Format(oldFileName.Substring(0, oldFileName.IndexOf("_") + 1) + DateTime.Now.ToString(), "yyyyMMddhhmmss").Replace(#"/", "").Replace(" ", "").Replace(":", "") + ".png";
As per your edit you are added .png to newFullFileName.. then newFullTempFolderURL will add another .png to your file name.
So ti will become FILENAME.png.png it will return wrong.
remove .png from newfullFilename and
try below
if (File.Exists( Path.Combine(Global.TempFolder, newFullFileName))
{
}
your File.Exists does not contain the file extension as you manually added it when creating "newFullTempFolderURL". You need to append ".png" to the File.Exists check or better yet use File.Exists(newFullTempFolderURL); as it's already been pre-made.
EDIT1:
You are adding ".png" a second time. This is wrong, as the file created is ".png.png", and then you are checking to see if ".png" exists.

How to programmatically convert a .cal file to a .cg4?

In windows explorer I am able to just change the file extension of a .cal file to a .cg4 file. When I do it I get a warning; "changing the file extension might render the file useless, do you still wish to change?" or something like that (OS not in english), but if I click "yes" it works.
But trying to do this programmatically with C# doesn't work. I get an error that states: "The given path's format is not supported."
I'm using File.Move for renaming/converting and that's where the error occurs.
File.Move(directory + fileNameWithoutExtension + ".cal", directory + fileNameWithoutExtension + ".cg4");
What can I do?
does this work?
var pathSource = System.IO.Path.Combine(directory, fileNameWithoutExtension, ".cal");
var pathDest = System.IO.Path.Combine(directory, fileNameWithoutExtension, ".cg4");
File.Move(pathSource, pathDest);
if it also throws an error, check if
fileNameWithoutExtension
already contains the data of
directory

How to get files from ressources folder to copy them in an other directory in C#?

Hello I would like to know if it was possible to extract the files from the ressources folder to copy thme in a directory at the moment i've tried this :
protected void Form1_Load(object sender, EventArgs e)
{
FileInfo info = new FileInfo(file);
info.CopyTo(PATH + "\\shell" + "\\" + file, true);
Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(file);
Image bitmap = Bitmap.FromFile(Environment.GetFolderPath (Environment.SpecialFolder.Desktop) + "ConnectableCORR\\ApplicationConnectTable\\Resources\\teapot.jpg");
bitmap.Save(Path.GetDirectoryName(PATH + "\\shell" + "\\" + "thumbnail_3D.png"), System.Drawing.Imaging.ImageFormat.Png);
}
But the copy isn't working am I doing anything wrong?
Best regards.
The method "Save" of object "Image" requires the name of file in "filename", and you are sending it:
Path.GetDirectoryName(PATH + "\\ shell" + "\\" + "thumbnail_3D.png")
Path.GetDirectoryName
Would return:
PATH + "\\ shell" + "\\"
Would fail the file name, you should also include the file name.
Edit
Try this and check the paths:
FileInfo info = new FileInfo(file);
MessageBox.Show(string.Format("File '{0}' exist '{1}'", info.FullName, info.Exists));
var destinationFile = string.Format("{0}\\shell\\{1}", PATH, file);
info.CopyTo(destinationFile, true);
MessageBox.Show(string.Format("File '{0}' exist '{1}'", destinationFile, File.Exists(destinationFile)));
I'm going to focus on the info.CopyTo() call, as that is the better way of your two options to copy the file. As it is written, there are a number of possibilities as to why it isn't working. For everything I'm thinking about, an exception would be thrown, so you should be able to add a try-catch block around your code and debug to see what the error is. Here's my best guesses, in the order I would try to debug them:
What is file? Is it a filename? Is it a full path plus filename? It looks to me like your code expects it to be fully-qualified in one place and just the name in another.
Source file doesn't exist. I would do a quick info.Exists to confirm that the file exists before trying to copy it.
Make sure the output filename makes sense. If file includes a path, then you really probably want to do info.CopyTo(PATH + "\\shell\\" + info.Name, true) unless you want to include the source path in the output path.
Output directory doesn't exist. If this is the case. A DirectoryNotFoundException will be thrown. Check if the directory exists and create it before doing your CopyTo.
Bad file name. Might contain invalid characters, which will cause either an ArgumentException or a NotSupportedException.
Path too long. Probably not this, but a PathTooLongException would be thrown.

Categories

Resources